feat(resource): Add childTemplate property for default child template#16898
feat(resource): Add childTemplate property for default child template#16898Ibochkarev wants to merge 2 commits intomodxcms:3.xfrom
Conversation
b7b3bf5 to
756ba00
Compare
…modxcms#13753) - Add resolveDefaultTemplate() and getChildTemplateIdFromParent() in Create processor - Add getChildTemplateIdFromParentTemplate() in resource create controller - When creating a child resource, use parent template's childTemplate property if set Resolves modxcms#13753
756ba00 to
b9bbc7f
Compare
Code ReviewSummaryAdds IssuesThe
AssessmentUseful feature, well-structured with early returns. But the code duplication is a significant maintainability concern. VerdictRequest changes — extract shared logic to eliminate duplication. |
- Introduced `getChildTemplateId()` method in `modTemplate` to encapsulate logic for retrieving the child template ID from a parent resource. - Updated `Create` processor and resource create controller to utilize the new method, simplifying the code by removing redundant methods. - Ensured that the child template ID is correctly resolved when creating child resources. This change enhances code maintainability and readability by consolidating the child template retrieval logic into a single method.
What does it do?
Adds support for the
childTemplatetemplate property. When creating a new child resource under a parent, if the parent's template has achildTemplateproperty set to a template ID, that template is preselected as the default for the new resource (both in the create form and when saving).Backend (
Resource/Createprocessor):resolveDefaultTemplate()andgetChildTemplateIdFromParent()read the parent template'schildTemplateproperty and use it when no template is explicitly provided.Manager (
resource/createcontroller):getChildTemplateIdFromParentTemplate()sets the default template in the create form. Takes precedence overautomatic_template_assignmentwhenchildTemplateis set.Why is it needed?
Allows template authors to define which template should be used for child resources (e.g. News overview → News detail), reducing manual template selection when creating documents in a hierarchy.
How to test
childTemplateproperty to a template (value = template ID).Related issue(s)/PR(s)
Resolves #13753