Templating: Creating a doctype with template now yields a strongly typed template (closes #20443)#20688
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.
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
...es/documents/document-types/repository/template/document-type-template.server.data-source.ts
Show resolved
Hide resolved
AndyButland
left a comment
There was a problem hiding this comment.
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.
- Add integration tests for ContentTypeService.CreateTemplateAsync: - Success case with template association - NotFound status for non-existent content type - InvalidTemplateAlias for empty and too-long aliases - Default template assignment verification - Fix bug in TemplateService.CreateAsync where alias validation occurred after GetViewContent call, causing ArgumentNullException for invalid aliases instead of returning InvalidAlias status 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
AndyButland
left a comment
There was a problem hiding this comment.
Additional tests and other small updates all look good, approving and merging this now.
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.