Skip to content

Commit

Permalink
Correctly show custom templates in "override all" mode (see #1007)
Browse files Browse the repository at this point in the history
Description
-----------

Fixes #938

Commits
-------

a15f7fd Correctly show custom templates in "override all" mode (see #938)
  • Loading branch information
leofeyer committed Nov 27, 2019
1 parent 3a82004 commit 1e08698
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core-bundle/src/Resources/contao/dca/tl_content.php
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,11 @@ public function getGalleryTemplates()
*/
public function getElementTemplates(Contao\DataContainer $dc)
{
if (Contao\Input::get('act') == 'overrideAll')
{
return $this->getTemplateGroup('ce_');
}

return $this->getTemplateGroup('ce_' . $dc->activeRecord->type . '_');
}

Expand Down
7 changes: 6 additions & 1 deletion core-bundle/src/Resources/contao/dca/tl_form_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,14 @@ public function getFields()
*/
public function getFormFieldTemplates(Contao\DataContainer $dc)
{
if (Contao\Input::get('act') == 'overrideAll')
{
return $this->getTemplateGroup('form_');
}

// Backwards compatibility
if ($dc->activeRecord->type == 'text')
{
// Backwards compatibility
return array_merge($this->getTemplateGroup('form_text_'), $this->getTemplateGroup('form_textfield_'));
}

Expand Down
5 changes: 5 additions & 0 deletions core-bundle/src/Resources/contao/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,11 @@ public function getNavigationTemplates()
*/
public function getModuleTemplates(Contao\DataContainer $dc)
{
if (Contao\Input::get('act') == 'overrideAll')
{
return $this->getTemplateGroup('mod_');
}

return $this->getTemplateGroup('mod_' . $dc->activeRecord->type . '_');
}

Expand Down
26 changes: 23 additions & 3 deletions core-bundle/src/Resources/contao/library/Contao/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,21 @@ public static function getTemplateGroup($strPrefix, array $arrAdditionalMapper=a
)
);

// Add templates that are not directly associated with a form field
$arrMapper['form'][] = 'row';
$arrMapper['form'][] = 'row_double';
$arrMapper['form'][] = 'xml';
$arrMapper['form'][] = 'wrapper';
$arrMapper['form'][] = 'message';
$arrMapper['form'][] = 'textfield'; // TODO: remove in Contao 5.0

// Add templates that are not directly associated with a module
$arrMapper['mod'][] = 'article';
$arrMapper['mod'][] = 'message';
$arrMapper['mod'][] = 'password'; // TODO: remove in Contao 5.0
$arrMapper['mod'][] = 'comment_form'; // TODO: remove in Contao 5.0
$arrMapper['mod'][] = 'newsletter'; // TODO: remove in Contao 5.0

// Get the default templates
foreach (TemplateLoader::getPrefixedFiles($strPrefix) as $strTemplate)
{
Expand Down Expand Up @@ -131,6 +146,8 @@ public static function getTemplateGroup($strPrefix, array $arrAdditionalMapper=a
// Add the customized templates
if (\is_array($arrCustomized))
{
$blnIsGroupPrefix = preg_match('/^[a-z]+_$/', $strPrefix);

foreach ($arrCustomized as $strFile)
{
$strTemplate = basename($strFile, strrchr($strFile, '.'));
Expand All @@ -148,11 +165,14 @@ public static function getTemplateGroup($strPrefix, array $arrAdditionalMapper=a

// Also ignore custom templates belonging to a different bundle template,
// e.g. mod_article and mod_article_list_custom
foreach ($arrBundleTemplates as $strKey)
if (!$blnIsGroupPrefix)
{
if (strpos($strTemplate, $strKey . '_') === 0)
foreach ($arrBundleTemplates as $strKey)
{
continue 2;
if (strpos($strTemplate, $strKey . '_') === 0)
{
continue 2;
}
}
}

Expand Down

0 comments on commit 1e08698

Please sign in to comment.