PR-5.0-dev Pending

User tests: Successful: Unsuccessful:

avatar hans2103
hans2103
30 May 2023

Pull Request for no issue

Summary of Changes

This PR will move logic and HTML to resp. MenuHelper and JLayouts.
With this PR one does not have to change 8 php files when changes to $linktype are in place.
Using the JLayout will make it easier to create overrides on the HTML used.

Testing Instructions

  • Joomla 5 with demo data
  • Adjust menu items to use icons and images too
  • Render the frontend
  • Apply path
  • Refresh the frontend in another screen
  • Compare HTML output

Actual result BEFORE applying this Pull Request

HTML output of mod_menu and cassiopeia/mod_menu should be equal.
Only the PHP logic behind has been changed and made DRY.

Expected result AFTER applying this Pull Request

Same as before, only with other PHP.

Link to documentations

Using the Google search "site:docs.joomla.org $linktype" I was able to find one single result. https://docs.joomla.org/J2.5:How_to_add_a_span_element_to_menu_entries
Using the Google search "site:manual.joomla.org $linktype" I was not able to find any reference of the php variable $linktype.
Therefor my conclusion that there are no documentation pages to be changed

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar joomla-cms-bot joomla-cms-bot - change - 30 May 2023
Category Layout Modules Front End Templates (site)
avatar hans2103 hans2103 - open - 30 May 2023
avatar hans2103 hans2103 - change - 30 May 2023
Status New Pending
avatar brianteeman
brianteeman - comment - 30 May 2023

This breaks all existing overrides with zero benefit

avatar dgrammatiko
dgrammatiko - comment - 30 May 2023

Please move all the layout files in the root of the module (ie: https://github.com/joomla/joomla-cms/tree/4.3-dev/administrator/components/com_categories/layouts). The root layout folder is supposed to be used for layouts that are global...

avatar hans2103
hans2103 - comment - 30 May 2023

This breaks all existing overrides with zero benefit

I agree that it will break all existing overrides. Therefor I've created this PR based on 5.0-dev instead of the current 4.x

I do not agree about the "zero benefit"

This PR simplifies the implementation of the creation of linktype. Why put logic to create the $linktype in 8 files? Not very DRY is it? Therefor a JLayout to replace 8 blocks of the same code to just one.

The following code

if ($item->menu_icon) {
    // The link is an icon
    if ($itemParams->get('menu_text', 1)) {
        // If the link text is to be displayed, the icon is added with aria-hidden
        $linktype = '<span class="p-2 ' . $item->menu_icon . '" aria-hidden="true"></span>' . $item->title;
    } else {
        // If the icon itself is the link, it needs a visually hidden text
        $linktype = '<span class="p-2 ' . $item->menu_icon . '" aria-hidden="true"></span><span class="visually-hidden">' . $item->title . '</span>';
    }
} elseif ($item->menu_image) {
    // The link is an image, maybe with its own class
    $image_attributes = [];

    if ($item->menu_image_css) {
        $image_attributes['class'] = $item->menu_image_css;
    }

    $linktype = HTMLHelper::_('image', $item->menu_image, $item->title, $image_attributes);

    if ($itemParams->get('menu_text', 1)) {
        $linktype .= '<span class="image-title">' . $item->title . '</span>';
    }
}

to

    public static function getLinktype($item, $itemParams)
    {
        $attributes = [
            'title'     => $item->title,
            'menu_text' => $itemParams->get('menu_text', 1),
        ];

        if ($item->menu_icon)
        {
            $attributes['icon'] = LayoutHelper::render('joomla.menu.icon', $item);
        }
        elseif ($item->menu_image)
        {
            $attributes['image']    = LayoutHelper::render('joomla.menu.image', $item);
        }

        return LayoutHelper::render('joomla.menu.linktype', $attributes);
    }

Please move all the layout files in the root of the module. The root layout folder is supposed to be used for layouts that are global...

I've tried modules/layouts/menu, but didn't see the output. After using echo LayoutHelper::debug( instead of `echo LayoutHelper::render( I've noticed that the JLayouts in module where not used.
I'll try again... just to be sure

avatar dgrammatiko
dgrammatiko - comment - 30 May 2023

I'll try again... just to be sure

It needs an attribute more, let me find an example:

// instead of this
 return LayoutHelper::render('joomla.menu.linktype', $attributes);

// do
return LayoutHelper::render('joomla.menu.linktype', $attributes, JPATH_ADMINISTRATOR . '/modules/mod_menu');

// Coming from: render($layoutFile, $displayData = null, $basePath = '', $options = null)

Also there's a sublayout so you don't have to call LayoutHelper::render() inside a layout:

    /**
     * Render a layout with the same include paths & options
     *
     * @param   string  $layoutId     The identifier for the sublayout to be searched in a subfolder with the name of the current layout
     * @param   mixed   $displayData  Data to be rendered
     *
     * @return  string  The necessary HTML to display the layout
     *
     * @since   3.2
     */
    public function sublayout($layoutId, $displayData)
avatar brianteeman
brianteeman - comment - 30 May 2023

no its not dry and maybe it should have been created dry in the first place by the people that implemented it. but its here now and I still dont see where the change has any benefit at all. but i do see a lot of negatives

avatar joomla-cms-bot joomla-cms-bot - change - 30 May 2023
Category Layout Modules Front End Templates (site) Modules Front End Templates (site)
avatar hans2103 hans2103 - change - 30 May 2023
Labels Added: PR-5.0-dev
avatar hans2103
hans2103 - comment - 30 May 2023

no its not dry and maybe it should have been created dry in the first place by the people that implemented it. but its here now and I still dont see where the change has any benefit at all. but i do see a lot of negatives

copied: maybe it should have been created dry in the first place

But it was not.. and I think that it should not hold us back to leave it as it is when we can make things DRY.

copied: i do see a lot of negatives

I think too.. This change has an impact on all mod_menu implementations.
Again... it should not hold the project back to improve the code.

avatar brianteeman
brianteeman - comment - 30 May 2023

once again - what are the benefits of this change and do they outweigh all the negatives.

avatar hans2103
hans2103 - comment - 30 May 2023

once again - what are the benefits of this change and do they outweigh all the negatives.

To prevent changes like these: #40675
Eight files had to be changed to get a single thing done.
After merging this PR only one file need to be changed.

Does it outweigh all the negatives? i do not know. I hope it does.

avatar HLeithner
HLeithner - comment - 31 May 2023

Thanks hans for your contribution, I see your point. But I don't see the benefit. mod_menu has already a layout system and building a menu is already expensive (server resources) enough. Adding (more?) layouts to the mix doesn't make too much sense for me. I have another approach for my own templates, splitting the code into multiple template files so they are better override able but don't think it's really needed.

Especially all the layouts you created have tivial code which could sit in the template it self if needed and doesn't need to create an overhead loading the layout. ymmv

avatar hans2103
hans2103 - comment - 31 May 2023

Thanks hans for your contribution, I see your point. But I don't see the benefit. mod_menu has already a layout system and building a menu is already expensive (server resources) enough. Adding (more?) layouts to the mix doesn't make too much sense for me. I have another approach for my own templates, splitting the code into multiple template files so they are better override able but don't think it's really needed.

Especially all the layouts you created have tivial code which could sit in the template it self if needed and doesn't need to create an overhead loading the layout. ymmv

Thank you for explaining the "no benefit" part with some excellent arguments. I like that. I see your point and will close this PR.

avatar hans2103 hans2103 - close - 31 May 2023
avatar hans2103 hans2103 - change - 31 May 2023
Status Pending Closed
Closed_Date 0000-00-00 00:00:00 2023-05-31 06:46:37
Closed_By hans2103

Add a Comment

Login with GitHub to post a comment