Error on disabling the "navigation_layout"

Created on 3 September 2024, 3 months ago
Updated 4 September 2024, 3 months ago

Problem/Motivation

I disabled some layouts using this module which works fine.

When hiding the navigation_layout an error is thrown:

The website encountered an unexpected error. Try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "navigation_layout" plugin does not exist. Valid plugin IDs for Drupal\Core\Layout\LayoutPluginManager are: layout_onecol, layout_twocol_bricks, layout_threecol_25_50_25, layout_threecol_33_34_33, layout_builder_blank in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (line 53 of core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

Seems like the navigation_layout does not exist but I do see it when using layout builder (see screenshots in attachment).

Steps to reproduce

Disable the navigation_layout

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇧🇪Belgium f0ns

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @f0ns
  • 🇧🇪Belgium f0ns

    So for reasons beyond my control the "navigation_layout" seems to exist (core module navigation) and is something that is considered needed.

    If that's the case it would be best to alter this module so you can't disable it (since it will throw the error I mention).

    For now I disabled this module and disabled / hide the layouts with the following code in case somebody has the same problem as I do.

    In this example I hide all the layouts except the one col layout.

    /**
     * Implements hook_layout_alter().
     */
    function YOUR_MODULE_layout_alter(&$definitions)
    {
        // an array of layouts to keep.
        $layoutsWhitelist = ['navigation_layout'];
    
        // layouts that are required and cannot be removed.
        $requiredLayouts = ['layout_onecol', 'layout_builder_blank'];
    
        $layouts = array_merge($requiredLayouts, $layoutsWhitelist);
        
        $definitions = array_filter(
            $definitions,
            static fn(string $id) => in_array($id, $layouts, true),
            ARRAY_FILTER_USE_KEY
        );
    }
    
    /**
     * Implements hook_preprocess_item_list__layouts().
     */
    function YOUR_MODULE_preprocess_item_list__layouts(&$variables)
    {
        // For some reason removing this layout breaks the website so we hide it.
        $layoutToHide = ['navigation_layout'];
    
        $variables['items'] = array_filter(
            $variables['items'],
            static fn(string $id) => !in_array($id, $layoutToHide, true),
            ARRAY_FILTER_USE_KEY
        );
    }
    
  • 🇧🇪Belgium f0ns

    I've added a patch to make sure "navigation_layout" can't be disabled anymore.

  • Status changed to Needs review 3 months ago
  • Status changed to RTBC 3 months ago
  • 🇵🇭Philippines paraderojether

    Hi f0ns,

    I reviewed patch #5, applied it against Layout disable 2.0.3, and confirmed the "navigation_layout" can't be disabled anymore.

    I added screenshots for reference.
    Thank you.

  • 🇧🇪Belgium f0ns

    Thank you for your swift reply and testing the patch.

    🙏

  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Please prepare this as MR and provide reference as inline comment to this issue and the code in core where navigation_layout is required. Thanks!

Production build 0.71.5 2024