-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Templating: Creating a doctype with template now yields a strongly typed template (closes #20443) #20688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ted for a content type Add id, name and alias to the request payload to allow creating multiple templates for the same document type Small adjustments Remove unused import and unnecessary async Switched content type template creation to content type controller Missing constant export # Conflicts: # src/Umbraco.Web.UI.Client/src/packages/core/backend-api/sdk.gen.ts
…does-not-yield-a-strongly-typed-template # Conflicts: # src/Umbraco.Web.UI.Client/src/packages/core/backend-api/sdk.gen.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the document type creation flow to prevent orphaned templates. Previously, templates were created before document types, which could leave orphaned templates if the document type creation failed. The new approach creates the document type first, then creates the template via a new Management API endpoint (POST /umbraco/management/api/v1/document-type/{id}/template). This ensures templates are only created for successfully persisted document types and allows the server to generate templates with the correct model reference.
Key changes:
- Introduces a new API endpoint for creating templates linked to specific document types
- Moves template creation logic to occur after document type creation
- Adds
CreateTemplateAsyncmethod toIContentTypeServiceandITemplateService
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| document-type-workspace.context.ts | Refactored _create to call template creation after document type creation; replaced direct template repository usage with document type template repository |
| document-type-template.repository.ts | New repository for managing document type-specific template operations |
| document-type-template.server.data-source.ts | New data source that calls the new Management API endpoint |
| types.ts | Added UmbDocumentTypeTemplateModel type definition |
| TemplateService.cs | Added new overload for CreateForContentTypeAsync accepting name, alias, and content type alias parameters |
| ContentTypeService.cs | Added CreateTemplateAsync method that creates a template and assigns it to a content type |
| CreateDocumentTypeTemplateController.cs | New API controller implementing the template creation endpoint |
| CreateDocumentTypeTemplateRequestModel.cs | Request model for the new endpoint |
| content-type-workspace-context-base.ts | Added reload() method to refresh workspace data |
| content-type-structure-manager.class.ts | Added reload() method to fetch latest content type data |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
src/Umbraco.Cms.Api.Management/Controllers/DocumentType/CreateDocumentTypeTemplateController.cs
Show resolved
Hide resolved
| ); | ||
|
|
||
| if (data) { | ||
| return { data: data as string }; |
Copilot
AI
Nov 25, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The return type is cast to string, but the API endpoint returns the template's GUID. The comment in the controller shows it returns the template key, not a string. This should likely be return { data: data as Guid } or the appropriate type representing a GUID.
AndyButland
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me @lauraneto, and tests out as expected. Just a couple of inline comments to consider, and a response to your question.
Just wonder if you might look at ContentTypeServiceTests and see if it's worth adding a test or two to cover the CreateTemplateAsync method you have added, and similar for CreateForContentTypeAsync added to TemplateService.
| { | ||
| TemplateOperationStatus.CancelledByNotification => ContentTypeOperationStatus | ||
| .CancelledByNotification, | ||
| TemplateOperationStatus.InvalidAlias => ContentTypeOperationStatus.InvalidAlias, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should introduce InvalidTemplateAlias as a new result option here? Just seeing as we have InvalidAlias and InvalidPropertyTypeAlias already.
Fixes #20443
In recent versions the flow of requests from the client when creating a document type with a template was:
In 1., the document type still didn't exist, so a "generic" template was being created.
Additionally, if the creation of the document type failed, the "orphan" template would remain.
This PR adds a new endpoint to the Management API:
With the above in place, I adjusted the flow to:
This way, a template is only created if the content type was actually created, and the generated template will know which model to reference.
The idea while building the new endpoint was also that you can also create templates for document types later on, default or not.
Testing
Create a Document Type with Template and verify that the generated template references the typed model and looks the same as in V13.
Also, ensure that creating templates through the backoffice still works as expected.