joomla / joomla-cms

Home of the Joomla! Content Management System
https://www.joomla.org
GNU General Public License v2.0
4.69k stars 3.63k forks source link

[4.2.5] Inheritance of template and template child overrides #39306

Open StefanSTS opened 1 year ago

StefanSTS commented 1 year ago

Steps to reproduce the issue

How I got to the issue:

  1. Make a child template.
  2. Create an override for collapse-metismenu.php in html/mod_menu/.
  3. Switch to child template.

Expected result

The override for mod_menu should work like given in the child template.

Actual result

The override of the child template is not working. You have to explicitely choose the child template override in the module.

System information (as much as possible)

PHP 8.0.x but doesn't matter I guess J 4.2.5

Additional comments

If a template introduces a new layout file like collapse-metismenu.php, it should be automatically overridden by a child template.

The names in the layout setting for the different files in mod_menu settings, advanced tab is a bit confusing too: Cassiopeia calls collapse-metismenu.php Collapsable Dropdown. The child template uses the file name to generate the name to choose: collapse-metismenu.

It's all a bit inconsistent.

I guess it is intended by Joomla to use all child template files automatically. So in advanced tab there might be a setting missing.

From cassiopeia/main template OR child -> missing From module -> is there From cassiopeia template -> is there From cassiopeia_child -> is there

Default setting should be the one that I declared as missing. Kind of an automatic setting. By default setting Joomla should take the template file/override or if available the child override file.

Template override available - no child override -> use template. Template override available - child override available -> use child. No template override - child override available -> use child. No template override - No child override -> use base module.

The problem at the moment: If someone would import a child template with various overrides, they would not work until every module is set to use the child template. I got aware of this problem by someone stating that the child template would not work. So this automatic setting would lead to a lot less user frustration.

dgrammatiko commented 1 year ago

Switch to child template.

How exactly did you did that part? Just by enabling the child as the default template? If so check that ALL the menus are also using the child template as the default. Enabling just a child as default template WILL NOT (by design) assign ALL menus to that template!

StefanSTS commented 1 year ago

I just enabled the child template and was expecting that all the overrides in the child template would work. It's a child template with basically just the mod_menu override. I just changed navbar navbar-expand-md to navbar navbar-expand-lg.

dgrammatiko commented 1 year ago

It's a child template with basically just the mod_menu override.

I think you're not getting what I'm trying to explain: the enable child as default template is not the same as assigning all the menus to the child template. Give it a try...

StefanSTS commented 1 year ago

I don't want to assign menus to the child template. The menus should be assigned to the parent template. I just want to add a different layout to a module. The parent should do the work, the child should change the layout.

richard67 commented 1 year ago

I don't want to assign menus to the child template. The menus should be assigned to the parent template. I just want to add a different layout to a module. The parent should do the work, the child should change the layout.

@StefanSTS This is not how it works. Your expectation is wrong.

StefanSTS commented 1 year ago

Maybe the system is too limited. I would expect everything not set on the child to be inherited from the parent. Saying my expectation is wrong expresses not too much motivation to think further. A simple automation of the inheritance could make the system so much simpler to use. Like in other Joomla template systems that use this for the last ten years.

brianteeman commented 1 year ago

Can you clairfy please. Are you saying that you have set the default site template style to be the child template and the module override is not working?

richard67 commented 1 year ago

Well, if that is the case, then it is indeed a bug, and I misunderstood. If not and the expected behavior makes sense, it would be a feature request. Anyway it could be that our documentation is not really complete.

StefanSTS commented 1 year ago

I have set the default site template style to be the child template and the module override for com_menu collapse-metismenu.php is not working. Only if I set the module layout explicitely to the child template it works. It might have to do with the fact that Cassiopeia introduces collapse-metismenu.php which is not present in core mod_menu.

brianteeman commented 1 year ago

ah got it - I understand what is happening now and why it is the expected behaviour

You have a module and it is set to use the cassiopeia module override/

You now create a child template and create a new override of the module

You set the child template as default

You expected the module that had been explicitly set to use a specific layout to magically change without you doing anything and to use a different layout in the child template.

If I have described everything correctly then it is not only expected behaviour but also the intended and desired behaviour.

StefanSTS commented 1 year ago

You expected the module that had been explicitly set to use a specific layout to magically change without you doing anything and to use a different layout in the child template.

Yes, I thought it would magically use child template's collapse-metismenu.php over parent template's collapse-metismenu.php.

In the same way as it magically changes when I make an override in Cassiopeia for mod_login/default.php. If I enable Cassiopeia it shows me "Hello Parent". If I enable Cassiopeia Child it shows me "Hello Child". Got the child activated here: https://php80.sts-hosting.de/j4vm3/ without changing layout settings in the advanced tab.

If I have described everything correctly then it is not only expected behaviour but also the intended and desired behaviour.

It might look like it is the expected behaviour, but it's not consistent compared to the behaviour of default.php. In case menu it does not override the parent. In case login it does override the parent. In both cases there is a set layout, once default(.php) From Module, once collapse-metismenu(.php) from Cassiopeia. The problem is either,

I send this now and read it again to understand myself.

StefanSTS commented 1 year ago

Tested another theory: Added collapse-metismenu.php to the core module. Used navbar-expand-sm. Cassiopeia has navbar-expand-md. Cassiopeia Child has navbar navbar-expand-lg.

Frontend shows -lg -> Showing the child template.

Setting in the module is set "explicitly" to From Module - collapse-metismenu.

This supports my theory that it only works when there is the same layout in the core module, because there you can explicitly set it to From Module, BUT explicitly or not, it uses Cassiopeia -> Cassiopeia Child.

Following this logic, I still expect that if the file is not in core, but I explicitly set the layout in Cassiopeia, it will be overridden by the child.

dgrammatiko commented 1 year ago

@StefanSTS check if https://github.com/joomla/joomla-cms/pull/39308 is what you are after.

@brianteeman @richard67 probably this change makes sense if the parent is the same as the defined specific override, maybe not. Anyways if this is something you're interested the same logic needs to be applied in 2 more files

richard67 commented 1 year ago

Well, I don’t want to make decisions. If it works and people like it and it gets tested, then ok for me.

richard67 commented 1 year ago

@dgrammatiko You mentioned two more places to be changed. So does it need to keep this issue open, and your PR solves only one part of it? Or is your PR ready and complete and we can close this issue lok. we usually do when having a PR?

dgrammatiko commented 1 year ago

You mentioned two more places to be changed.

The layout part is similar for modules/plugins and components, so naturally if one is changed the other 2 need to be adjusted for consistency. The files/methods are: https://github.com/joomla/joomla-cms/blob/2a02425af5341bacc4658562543051c40f24fefe/libraries/src/Plugin/PluginHelper.php#L48 https://github.com/joomla/joomla-cms/blob/2a02425af5341bacc4658562543051c40f24fefe/libraries/src/MVC/View/HtmlView.php#L355

I think the issue should be closed when either a decision to adapt or not is made from the maintainers. FWIW I think the change asked here is reasonable...

richard67 commented 1 year ago

I‘ll ask the team for a decision.

richard67 commented 1 year ago

… Or at least for more opinions.

martyharty commented 5 months ago

I experienced a similar bug with a default child template of Atum admin template and com_menus/item/edit.php

But in this case also the control panel/ homepage is opened with the parent Atum template instead of the default child.

Other menus work fine.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/39306.