Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: HeCAPTe 1.0.2 — Minor update available for module hecapte_captcha (1.0.2). Release: Attribution & Licensing 1.2.1 — Minor update available for module attribution (1.2.1). Release: MCP Sentinel 2.29.0 — Minor update available for module mcp_sentinel (2.29.0). Release: Audit Chain 1.10.9 — Minor update available for module audit_chain (1.10.9). Release: Menu Autopilot 1.4.7 — Minor update available for module menu_autopilot (1.4.7). Release: FileGate 1.11.3 — Minor update available for module file_gate (1.11.3). Release: Download Tracker 1.0.7 — Minor update available for module download_tracker (1.0.7). Release: Directory2Block Slideshow 1.0.8 — Minor update available for module directory2block_slideshow (1.0.8). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

Simple Mega Menu

Security covered Drupal 10–11
View on drupal.org

Simple Mega Menu module provide a easy way to build mega menu. This module does not attempt to generate a finished mega menu, which can then be difficult to customize. Instead it provides some fondations to build easily a mega menu with Twig and some content entities.

If you're looking for a plug and play solution, this is not the module for you. But if you're looking for an easy way to place custom content (link, image, text, etc.) inside a menu, this module could be for you.

Currently, a simple mega menu entity can only be selected from a menu link content (a menu link created manually). Menu link items created by modules can't be supported for now. Waiting #2656534: Provide a way to extract a menu plugin from a menu form

How it works

This module provides a new content entity type, Simple MegaMenu. These entities can be managed as the node entity type : Create bundle, add view mode, add fields, customize display, etc. For each bundle created, you have to specify on which menu this bundle will be available.

You can then reference, from each Menu link content item, any entities available for this bundle.

Foreach menu that has been set on a Simple Mega Menu bundle, this module overrides the default template twig menu.html.twig with a template menu--simple-megamenu.html.twig similar but with some new Twig functions used as a default / starting template.

The simple MegaMenu entity attached to an item is then rendered from the Twig template provided by the module. To achieve this, two new Twig functions are available :

  • view_megamenu(Url $url, 'view_mode') : this function allows to render the simple MegaMenu entity attached to an item url, in any view mode needed.
  • has_megamenu(Url $url) : this function allows you to check if an item has a Simple MegaMenu entity attached to it.

You can then easily customize how your megamenu looks like by overriding the Twig template in your theme.

By default, the module provide two view modes for the simple mega menu entity type : Before and After

The default template use theses two view modes

{# File menu--simple-megamenu.html.twig #}
{{ attach_library('simple_megamenu/base') }}
{{ 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', 'menu--simple-mega-menu') }}>
    {% else %}
      <ul {{ attributes.removeClass('menu--simple-mega-menu') }}>
    {% endif %}
    {% for item in items %}
      {%
        set classes = [
          'menu-item',
          item.is_expanded ? 'menu-item--expanded',
          item.is_collapsed ? 'menu-item--collapsed',
          item.in_active_trail ? 'menu-item--active-trail',
        ]
      %}
      <li{{ item.attributes.addClass(classes) }}>
        {{ link(item.title, item.url) }}
        {% if item.below %}
          {% if has_megamenu(item.url) %}
            <div class="mega-menu-wrapper">
              {{ view_megamenu(item.url, 'before') }}
              {{ menus.menu_links(item.below, attributes.addClass('mega-menu-item'), menu_level + 1) }}
              {{ view_megamenu(item.url, 'after') }}
            </div>
          {% else %}
            {{ menus.menu_links(item.below, attributes.removeClass('mega-menu-item'), menu_level + 1) }}
          {% endif %}
        {% endif %}
      </li>
    {% endfor %}
    </ul>
  {% endif %}
{% endmacro %}

You can then easily update your custom template and use any custom view mode you want, to feet your needs. And you can too render entities attached where you want.

Simple MegaMenu entities are translatable and revisionable and play nice with a mutlilingual site.

Styling

Simple Mega Menu provide basic styling. You can override the library (css/js) provided by this module simply by adding theses lines into your theme file my_theme.info.yml

libraries-override:
  # Replace an entire library.
  simple_megamenu/base: my_theme/megamenu

where my_theme/megamenu is your own library. See the Drupal 8 Theming documentation for further details.

Documentation

A blog post explain how to create a mega menu with this module.

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

1 tracked project depends on this one

Activity

Tracked releases
4
Tracked since
Mar 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Release Timeline

Releases

Version Type Core Release date
3.0.x-dev Dev 10–11 Sep 9, 2024
2.2.0 Stable 10–11 Sep 9, 2024
2.1.x-dev Dev Mar 10, 2023
2.1.0 Stable Mar 10, 2023