Drupal is a registered trademark of Dries Buytaert
Release: Drupal 10.3.6 Update released for Drupal core (10.3.6)! Release: Drupal 11.0.5 Update released for Drupal core (11.0.5)! Release: Drupal 10.2.9 Update released for Drupal core (10.2.9)! Release: Drupal 10.2.10 Update released for Drupal core (10.2.10)! Release: Drupal 10.3.7 Update released for Drupal core (10.3.7)! Release: Drupal 11.0.6 Update released for Drupal core (11.0.6)! Release: Drupal 10.3.8 Update released for Drupal core (10.3.8)! Release: Drupal 11.0.7 Update released for Drupal core (11.0.7)! Module Revived: Translation Management Tool 8.x-1.19 Module tmgmt updated after 7 months of inactivity (8.x-1.19). Usage Milestone: Account field split Module account_field_split crossed 10,000 active installs.

Patch #75 is available for Drupal 9.1.x and it works! You might want to use skip this module and use the patch instead if you only want to filter menu by language.

This module started as a workaround to this 6+ years old issue in core. It helps site builders to easily filter menu by language with a few clicks and it provides developers with a custom service to manipulate menus (see example in code).

Current available manipulators

  • Add custom icon to menu items
  • Filter menu items by current language
  • ...anything else you'd like this module to do? (open an issue)

How to install

composer require drupal/menu_manipulator
drush en menu_manipulator -y

How to use

Go to Admin > Configuration > User Interface.

Filter by language

Select which menus have to be filtered by language. Menu items will be hidden if not translated into the current language OR if they points to an entity which does not have translation for the current language.

Menu icons

Populate the custom list in settings and select which menus should have icons.

Edit your menu items and select an icon from the dropdown list.

Icon will be available in your Twig template as follow:

    {% for item in items %}
      <li{{ item.attributes }}>
        {# If, for any reason, item.icon is empty, you can retrieve it like this: #}
        {% set icon = item['#icon'] ?: item.original_link.getOptions().icon %} 

        {# Embed icon inside link text #}
        {% set link_text %}
          {% if icon %}
            {# Example of an SVG icon as a Twig template #}
            {% include '@yourtheme/icons/icon.html.twig' with { icon: icon } %}

            {# Example of icon as CSS background image #}
            <span class="icon icon--{{ icon }}"></span>

            {# Hide the text #}
            <span class="visually-hidden">{{ item.title }}</span>
          {% else %}
            {# No icon, display the text only #}
            <span class="menu-item-label">{{ item.title|raw }}</span>
          {% endif %}
        {% endset %}

        {{ link(link_text, item.url) }}

        {% if item.below %}
          {{ menus.menu_links(item.below, attributes, menu_level + 1) }}
        {% endif %}

      </li>
    {% endfor %}

Known issues

  • Apply this patch to fix the compatibility issue with SuperFish module

Recommended/complementary modules

Similar projects

Any questions? Found a bug? Need another menu manipulator?
Please create a new issue here.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Dec 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Core Release date
4.0.0 Stable Dec 17, 2024
3.1.0 Stable Dec 17, 2024