Skip to content

Commit ae19f06

Browse files
[6.1] Implement copy child template (#46278)
Co-authored-by: Brian Teeman <[email protected]>
1 parent 3271ef0 commit ae19f06

File tree

6 files changed

+17
-11
lines changed

6 files changed

+17
-11
lines changed

administrator/components/com_templates/src/Model/TemplateModel.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,11 @@ protected function fixTemplateName()
824824
$oldName = $template->element;
825825
$manifest = json_decode($template->manifest_cache);
826826

827+
// When copying a child template we need to prefix it with the parent template name
828+
if (!empty($template->xmldata->parent)) {
829+
$newName = $template->xmldata->parent . '_' . $newName;
830+
}
831+
827832
foreach ($files as $file) {
828833
$newFile = '/' . str_replace($oldName, $newName, basename($file));
829834

@@ -2042,14 +2047,16 @@ public function child()
20422047
$media->addChild('folder', 'images');
20432048
$media->addChild('folder', 'scss');
20442049

2045-
$xml->name = $template->element . '_' . $newName;
2050+
$element = (!empty($template->xmldata->parent) ? $template->xmldata->parent : $template->element);
2051+
2052+
$xml->name = $element . '_' . $newName;
20462053

20472054
if (isset($xml->namespace)) {
20482055
$xml->namespace .= '_' . ucfirst($newName);
20492056
}
20502057

20512058
$xml->inheritable = 0;
2052-
$files = $xml->addChild('parent', $template->element);
2059+
$files = $xml->addChild('parent', $element);
20532060

20542061
$dom = new \DOMDocument();
20552062
$dom->preserveWhiteSpace = false;

administrator/components/com_templates/src/View/Template/HtmlView.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,9 @@ protected function addToolbar()
275275
// Add a copy/child template button
276276
if (isset($this->template->xmldata->inheritable) && (string) $this->template->xmldata->inheritable === '1') {
277277
ToolbarHelper::modal('childModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_TEMPLATE_CHILD');
278-
} elseif (empty($this->template->xmldata->parent) && empty($this->template->xmldata->namespace)) {
279-
// We can't copy parent templates nor namespaced templates
280-
ToolbarHelper::modal('copyModal', 'icon-copy', 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE');
278+
} elseif (empty($this->template->xmldata->namespace)) {
279+
// We can't copy namespaced templates
280+
ToolbarHelper::modal('copyModal', 'icon-copy', !empty($this->template->xmldata->parent) ? 'COM_TEMPLATES_BUTTON_COPY_CHILD_TEMPLATE' : 'COM_TEMPLATES_BUTTON_COPY_TEMPLATE');
281281
}
282282

283283
break;

administrator/components/com_templates/tmpl/template/default.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@
394394
$copyModalData = [
395395
'selector' => $taskName . 'Modal',
396396
'params' => [
397-
'title' => Text::_('COM_TEMPLATES_TEMPLATE_' . strtoupper($taskName)),
397+
'title' => Text::_('COM_TEMPLATES_TEMPLATE_' . strtoupper($taskName) . (isset($this->template->xmldata->parent) && (string) $this->template->xmldata->parent !== '' ? '_CHILD' : '')),
398398
'footer' => $this->loadTemplate('modal_' . $taskName . '_footer')
399399
],
400400
'body' => $this->loadTemplate('modal_' . $taskName . '_body')

administrator/components/com_templates/tmpl/template/default_modal_copy_footer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414

1515
?>
1616
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal"><?php echo Text::_('COM_TEMPLATES_TEMPLATE_CLOSE'); ?></button>
17-
<button type="submit" class="btn btn-primary"><?php echo Text::_('COM_TEMPLATES_TEMPLATE_COPY'); ?></button>
17+
<button type="submit" class="btn btn-primary"><?php echo Text::_('COM_TEMPLATES_TEMPLATE_COPY' . (isset($this->template->xmldata->parent) && (string) $this->template->xmldata->parent !== '' ? '_CHILD' : '')); ?></button>

administrator/language/en-GB/com_templates.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ COM_TEMPLATES_BUTTON_CHECK="Check Overrides"
1111
COM_TEMPLATES_BUTTON_CHECK_LIST_ENTRY="Mark Checked"
1212
COM_TEMPLATES_BUTTON_CLOSE_FILE="Close"
1313
COM_TEMPLATES_BUTTON_COPY_FILE="Copy File"
14+
COM_TEMPLATES_BUTTON_COPY_CHILD_TEMPLATE="Copy Child Template"
1415
COM_TEMPLATES_BUTTON_COPY_TEMPLATE="Copy Template"
1516
COM_TEMPLATES_BUTTON_CREATE="Create"
1617
COM_TEMPLATES_BUTTON_CROP="Crop"
@@ -240,6 +241,7 @@ COM_TEMPLATES_TEMPLATE_CHILD_NAME_LABEL="Child Template Name"
240241
COM_TEMPLATES_TEMPLATE_CHILD_STYLE_LABEL="Additional Template Styles"
241242
COM_TEMPLATES_TEMPLATE_CLOSE="Close"
242243
COM_TEMPLATES_TEMPLATE_COPY="Copy Template"
244+
COM_TEMPLATES_TEMPLATE_COPY_CHILD="Copy Child Template"
243245
COM_TEMPLATES_TEMPLATE_CORE_FILENAME="Original file &quot;%s&quot;."
244246
COM_TEMPLATES_TEMPLATE_DESCRIPTION="Template description."
245247
COM_TEMPLATES_TEMPLATE_DETAILS="%s Details and Files"

templates/cassiopeia_extended/templateDetails.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</files>
2020
<media destination="templates/site/cassiopeia_extended" folder="media">
2121
<folder>css</folder>
22+
<folder>images</folder>
2223
<folder>scss</folder>
2324
</media>
2425
<positions>
@@ -42,10 +43,6 @@
4243
<position>error-403</position>
4344
<position>error-404</position>
4445
</positions>
45-
<languages folder="language">
46-
<language tag="en-GB">en-GB/tpl_cassiopeia.ini</language>
47-
<language tag="en-GB">en-GB/tpl_cassiopeia.sys.ini</language>
48-
</languages>
4946
<config>
5047
<fields name="params">
5148
<fieldset name="advanced">

0 commit comments

Comments
 (0)