Skip to content
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
706d42f
styles
dgrammatiko Dec 7, 2021
8603123
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 7, 2021
3d56717
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Dec 7, 2021
050ac22
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 7, 2021
b3c201a
Freely select to also copy styles from parent or childs (of the same …
dgrammatiko Dec 7, 2021
a7856e2
cleanup
dgrammatiko Dec 7, 2021
4ba0aff
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 8, 2021
9eaf07c
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 12, 2021
4befc13
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 13, 2021
9acb7c4
Update administrator/components/com_templates/tmpl/template/default_m…
dgrammatiko Dec 13, 2021
9372e14
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 16, 2021
4192e5e
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 21, 2021
a33821b
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 30, 2021
c5cf9ae
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Dec 30, 2021
ba165b0
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Jan 1, 2022
89ff152
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
bembelimen Jan 6, 2022
1b97651
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Jan 10, 2022
a369f29
update
dgrammatiko Jan 10, 2022
1e10fab
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 10, 2022
1b4d992
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 10, 2022
70e5d39
Update administrator/components/com_templates/tmpl/template/default_m…
dgrammatiko Jan 10, 2022
4dac672
Update administrator/language/en-GB/com_templates.ini
dgrammatiko Jan 10, 2022
1d9073a
Update administrator/components/com_templates/src/View/Template/HtmlV…
dgrammatiko Jan 10, 2022
b2a3215
Update administrator/components/com_templates/src/Controller/Template…
dgrammatiko Jan 10, 2022
c0b3284
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 10, 2022
72b12ac
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 10, 2022
c04e334
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 10, 2022
b2d9079
sprintf
dgrammatiko Jan 10, 2022
686e9eb
txt
dgrammatiko Jan 10, 2022
ad86e38
oops
dgrammatiko Jan 11, 2022
728d6e8
Update administrator/language/en-GB/com_templates.ini
dgrammatiko Jan 11, 2022
23ef9d0
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Jan 11, 2022
461263f
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Jan 16, 2022
6f955fa
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Jan 24, 2022
fa56b70
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
dgrammatiko Feb 2, 2022
77000b7
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
rdeutz Mar 16, 2022
8d50de4
Merge branch '4.1-dev' into 4.1-dev-child-with-existing-styles
laoneo Apr 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1008,10 +1008,12 @@ public function child()

$this->input->set('installtype', 'folder');
$newNameRaw = $this->input->get('new_name', null, 'string');

// Only accept letters, numbers and underscore for template name
$newName = preg_replace('/[^a-zA-Z0-9_]/', '', $newNameRaw);
$templateID = (int) $this->input->getInt('id', 0);
$file = (string) $this->input->get('file', '', 'cmd');
$newName = preg_replace('/[^a-zA-Z0-9_]/', '', $newNameRaw);
$templateID = (int) $this->input->getInt('id', 0);
$file = (string) $this->input->get('file', '', 'cmd');
$extraStyles = (array) $this->input->get('style_ids', [], 'array');

$this->setRedirect('index.php?option=com_templates&view=template&id=' . $templateID . '&file=' . $file);

Expand Down Expand Up @@ -1083,6 +1085,12 @@ public function child()
$this->setMessage(Text::sprintf('COM_TEMPLATES_CHILD_SUCCESS', $newName));
$model->cleanup();

if (\count($extraStyles) > 0)
{
$model->setState('stylesToCopy', $extraStyles);
$model->copyStyles();
}

return true;
}
}
107 changes: 100 additions & 7 deletions administrator/components/com_templates/src/Model/TemplateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Joomla\Component\Templates\Administrator\Helper\TemplateHelper;
use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper;
use Joomla\Database\ParameterType;
use Joomla\Utilities\ArrayHelper;

/**
* Template model class.
Expand Down Expand Up @@ -2045,7 +2046,6 @@ private function getBasePath()
JPATH_ROOT . '/' . ($this->template->client_id === 0 ? '' : 'administrator/') . 'templates/' . $this->template->element;
}


/**
* Method to create the templateDetails.xml for the child template
*
Expand Down Expand Up @@ -2169,6 +2169,8 @@ public function child()
$media->addChild('folder', 'css');
$media->addChild('folder', 'js');
$media->addChild('folder', 'images');
$media->addChild('folder', 'html');
$media->addChild('folder', 'scss');

$xml->name = $template->element . '_' . $newName;
$xml->inheritable = 0;
Expand All @@ -2189,24 +2191,115 @@ public function child()
}

// Create an empty media folder structure
if (!Folder::create($toPath . '/media'))
if (!Folder::create($toPath . '/media')
|| !Folder::create($toPath . '/media/css')
|| !Folder::create($toPath . '/media/js')
|| !Folder::create($toPath . '/media/images')
|| !Folder::create($toPath . '/media/html/tinymce')
|| !Folder::create($toPath . '/media/scss'))
{
return false;
}

if (!Folder::create($toPath . '/media/css'))
return true;
}

/**
* Method to get the parent template existing styles
*
* @return array array of id,titles of the styles
*
* @since __DEPLOY_VERSION__
*/
public function getAllTemplateStyles()
{
$template = $this->getTemplate();

if (!$template->xmldata->inheritable)
{
return false;
return [];
}

if (!Folder::create($toPath . '/media/js'))
$db = $this->getDbo();
$query = $db->getQuery(true);

$query->select($db->quoteName(['id', 'title']))
->from($db->quoteName('#__template_styles'))
->where($db->quoteName('client_id') . ' = :client_id', 'AND')
->where($db->quoteName('template') . ' = :template')
->orWhere($db->quoteName('parent') . ' = :parent')
->bind(':client_id', $template->client_id, ParameterType::INTEGER)
->bind(':template', $template->element)
->bind(':parent', $template->element);

$db->setQuery($query);

return $db->loadObjectList();
}

/**
* Method to copy selected styles to the child template
*
* @return boolean true if name is not used, false otherwise
*
* @since __DEPLOY_VERSION__
*/
public function copyStyles()
{
$app = Factory::getApplication();
$template = $this->getTemplate();
$newName = strtolower($this->getState('new_name'));
$applyStyles = $this->getState('stylesToCopy');

// Get a db connection.
$db = $this->getDbo();

// Create a new query object.
$query = $db->getQuery(true);

$query->select([$db->quoteName('title'), $db->quoteName('params')])
->from($db->quoteName('#__template_styles'))
->whereIn($db->quoteName('id'), ArrayHelper::toInteger($applyStyles));
// Reset the query using our newly populated query object.
$db->setQuery($query);

try
{
$parentStyle = $db->loadObjectList();
}
catch (\Exception $e)
{
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_STYLE_NOT_FOUND'), 'error');

return false;
}

if (!Folder::create($toPath . '/media/images'))
foreach ($parentStyle as $style)
{
return false;
$query = $db->getQuery(true);
$styleName = Text::sprintf('COM_TEMPLATES_COPY_CHILD_TEMPLATE_STYLES', ucfirst($template->element . '_' . $newName), $style->title);

// Insert columns and values
$columns = ['id', 'template', 'client_id', 'home', 'title', 'inheritable', 'parent', 'params'];
$values = [0, $db->quote($template->element . '_' . $newName), (int) $template->client_id, $db->quote('0'), $db->quote($styleName), 0, $db->quote($template->element), $db->quote($style->params)];

$query
->insert($db->quoteName('#__template_styles'))
->columns($db->quoteName($columns))
->values(implode(',', $values));

$db->setQuery($query);

try
{
$db->execute();
}
catch (\Exception $e)
{
$app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_COULD_NOT_READ'), 'error');

return false;
}
}

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public function display($tpl = null)
$this->preview = $this->get('Preview');
$this->pluginState = PluginHelper::isEnabled('installer', 'override');
$this->updatedList = $this->get('UpdatedList');
$this->styles = $this->get('AllTemplateStyles');
$this->stylesHTML = '';

$params = ComponentHelper::getParams('com_templates');
$imageTypes = explode(',', $params->get('image_formats'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,52 @@

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;

Factory::getDocument()->getWebAssetManager()->usePreset('choicesjs');

// Generate a list of styles for the child creation modal
$options = [];

if (count($this->styles) > 0)
{
foreach ($this->styles as $style)
{
$options[] = HTMLHelper::_('select.option', $style->id, $style->title, 'value', 'text');
}
}

$fancySelectData = [
'autocomplete' => 'off',
'autofocus' => false,
'class' => '',
'description' => '',
'disabled' => false,
'group' => false,
'id' => 'style_ids',
'hidden' => false,
'hint' => '',
'label' => '',
'labelclass' => '',
'onchange' => '',
'onclick' => '',
'multiple' => true,
'pattern' => '',
'readonly' => false,
'repeat' => false,
'required' => false,
'size' => 4,
'spellcheck' => false,
'validate' => '',
'value' => '0',
'options' => $options,
'dataAttributes' => [],
'dataAttribute' => '',
'name' => 'style_ids[]',
];
?>
<div id="template-manager-copy" class="container-fluid">
<div class="mt-2">
Expand All @@ -28,6 +72,19 @@
</small>
</div>
</div>
<div class="control-group">
<div class="control-label">
<label for="style_ids">
<?php echo Text::_('COM_TEMPLATES_TEMPLATE_CHILD_STYLE_LABEL'); ?>
</label>
</div>
<div class="controls">
<?php echo LayoutHelper::render('joomla.form.field.list-fancy-select', $fancySelectData); ?>
<small class="form-text">
<?php echo Text::_('COM_TEMPLATES_TEMPLATE_NEW_STYLE_DESC'); ?>
</small>
</div>
</div>
</div>
</div>
</div>
3 changes: 3 additions & 0 deletions administrator/language/en-GB/com_templates.ini
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ COM_TEMPLATES_CONFIG_SOURCE_LABEL="Valid Source Formats"
COM_TEMPLATES_CONFIG_UPLOAD_LABEL="Max. Upload Size (MB)"
COM_TEMPLATES_CONFIGURATION="Template: Options"
COM_TEMPLATES_COPY_SUCCESS="New template called %s was installed."
COM_TEMPLATES_COPY_CHILD_TEMPLATE_STYLES="%s, copy of %s"
COM_TEMPLATES_CROP_AREA_ERROR="Crop area not selected."
COM_TEMPLATES_DIRECTORY_NOT_WRITABLE="The template folder is not writable. Some features may not work."
COM_TEMPLATES_ERR_XML="Template XML data not available"
Expand Down Expand Up @@ -218,6 +219,8 @@ COM_TEMPLATES_TAB_OVERRIDES="Create Overrides"
COM_TEMPLATES_TAB_UPDATED_FILES="Updated Files"
COM_TEMPLATES_TEMPLATE_CHILD="Child Template"
COM_TEMPLATES_TEMPLATE_CHILD_NAME_LABEL="Child Template Name"
COM_TEMPLATES_TEMPLATE_CHILD_STYLE_LABEL="Additional Template Styles"
COM_TEMPLATES_TEMPLATE_NEW_STYLE_DESC="Duplicate existing styles for the new child template."
COM_TEMPLATES_TEMPLATE_CLOSE="Close"
COM_TEMPLATES_TEMPLATE_COPY="Copy Template"
COM_TEMPLATES_TEMPLATE_CORE_FILENAME="Original file &quot;%s&quot;."
Expand Down