Follow-up to #2422363: Rewrite the menu CSS components inline with our CSS standards

Problem/Motivation

Majority of users don't use the .leaf/.menu-item--leaf class and it's not used in core.

Proposed resolution

  • Remove references to leaf in core in a patch.
  • Write an example to add this back in through either in a menu-tree.html.twig template override or preprocess.

Remaining tasks

User interface changes

Removal of unnessasary class for majority of theming needs. Alternative method of implementing .leaf in template provided.

API changes

None

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task because coding standards
Unfrozen changes Unfrozen because it only changes HTML/CSS

Comments

joelpittet’s picture

Issue summary: View changes
Issue tags: +Novice
nitvirus’s picture

Hi,

So I just have to Remove .leaf/.menu-item--leaf from menu CSS components and upload the patch.
Could you please help me in writing the example: what exactly needs to there in example?

Thanks,
Nit

joelpittet’s picture

@nitvirus yes just remove leaf from where it's set in the CSS and the PHP and comments referencing it if there are any.

To add it back, I'd look at the menu-tree.html.twig and see how you can acheive the same thing inside the template. Something like counting the children == 0 then adding a class using attributes.addClass() in twig should do the trick.

@mortendk, may be around to help as well, ask for him on IRC.

pjbaert’s picture

Status: Active » Needs review
StatusFileSize
new977 bytes

I removed the .leaf reference out the MenuLinkTree.php file.
I did find a reference to .leaf class in Seven theme but I don't think removing this breaks anything.

I'm still working on the example because I noticed that the menu-tree.html.twig was removed in #1777332: Replace theme_menu_link() and menu-tree.html.twig with a single Twig template

Status: Needs review » Needs work

The last submitted patch, 4: remove-leaf-2425691-4.patch, failed testing.

Status: Needs work » Needs review
joelpittet’s picture

Status: Needs review » Needs work

Thanks @pjbaert, There is one more reference in the book module. Could you do a search for any other reference to leaf in core?

I know there is a tabledrag-leaf, that can be ignored for the scope of this patch.

drupalninja99’s picture

Status: Needs work » Needs review
StatusFileSize
new1.5 KB
new557 bytes

Here is an updated patch with the leaf reference removed from the book module.

kepford’s picture

StatusFileSize
new1.19 KB
new2.14 KB

Updated the patch to remove all references from the Book module.

davidhernandez’s picture

Status: Needs review » Needs work

I'm not seeing any other references to the leaf class so that's good. We just need the example text.

pjbaert’s picture

StatusFileSize
new1.39 KB

I think this example should cover this.
This doesn't reproduce the old behaviour since the 'below' variable is limited to the 'maximum number of menu levels to display' we set in the menu block configuration.

In my opinion this is the right behaviour since it's not displaying any children elements.

pjbaert’s picture

Status: Needs work » Needs review
joelpittet’s picture

@pjbaert Thank you! That looks like what I would do!

Maybe we can get @mortendk to test it out.

mortendk’s picture

Assigned: Unassigned » mortendk

lemme grap

mortendk’s picture

Issue summary: View changes

Ok after playing a bit with it and getting the menu to crash on me hard, i rewrote #11 & added the only leaf class there should ever be ;)

menu.html.twig

{% import _self as menus %}

{#
  We call a macro which calls itself to render the full tree.
  @see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}

{% macro menu_links(items, attributes, menu_level) %}
  {% import _self as menus %}
  {% if items %}
    {% if menu_level == 0 %}
      <ul{{ attributes.addClass('menu') }}>
    {% else %}
      <ul class="menu">
    {% endif %}
      {% for item in items %}

          {#
            test if theres more menu items to be printed
            if there is add a class for it
          #}
          {% if item.below|length == 0 %}
            <li{{ item.attributes.addClass('im-like-a-leaf-on-the-wind') }}>
          {% else %}
            <li{{ item.attributes }}>
          {% endif %}

          {# print out the link & test if theres more items #}
          {{ link(item.title, item.url) }}
          {% if item.below %}
            {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
          {% endif %}
        </li>
      {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

This is a screenshot from d8 right now without the menu cleanup & this patch to remove the .leaf that are flying around (see what i did there ... )

Only local images are allowed.

mortendk’s picture

Assigned: mortendk » Unassigned

ungraps + bonus points for knowing where the leaf reference is coming from

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Beauty:) Much simipler approach and doesn't needlessly add a class that is rarely if ever used!

We just need to find a documentation page to add your example to it after commit. Thank you all!

davidhernandez’s picture

Maybe a change record or add the sample text to this issue summary and then add a line here? https://www.drupal.org/node/2356951

joelpittet’s picture

Issue summary: View changes
pjbaert’s picture

I'm getting the reference @mortendk
Isn't it the scene from Serenity where Hoban 'Wash' get's killed?

mortendk’s picture

@pjbart ! yes +1 in epic geek points ;)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs change record

Write an example to add this back in through either in a menu-tree.html.twig template override or preprocess.

Let's put this in a CR then...

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community
Issue tags: -Needs change record
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Sorry I'm going to be a pain in the ... can we merge the CR for #2422363: Rewrite the menu CSS components inline with our CSS standards with CR for this one? Less CRs is a good thing and these are on the same topic.

davidhernandez’s picture

Status: Needs work » Reviewed & tested by the community

I merged the CRs.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

With the changes in #2422363: Rewrite the menu CSS components inline with our CSS standards isn't a leaf also...

.menu-item:not(.menu-item--expanded):not(.menu-item--collapsed)

Let's publish the CR after the other issue goes in.

CSS and templates are not frozen in beta. Committed 9e21230 and pushed to 8.0.x. Thanks!

  • alexpott committed 9e21230 on 8.0.x
    Issue #2425691 by pjbaert, kepford, drupalninja99: Remove .leaf/.menu-...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.