function NavigationHooks::blockAlter

Implements hook_block_alter().

File

core/modules/navigation/src/Hook/NavigationHooks.php, line 155

Class

NavigationHooks
Hook implementations for navigation.

Namespace

Drupal\navigation\Hook

Code

public function blockAlter(&$definitions) : void {
    array_walk($definitions, function (&$definition, $block_id) {
        [
            $base_plugin_id,
        ] = explode(PluginBase::DERIVATIVE_SEPARATOR, $block_id);
        // Add the allow_in_navigation attribute to those blocks valid for Navigation.
        // @todo Refactor to use actual block Attribute once
        //   https://www.drupal.org/project/drupal/issues/3443882 is merged.
        $allow_in_navigation = [
            'navigation_user',
            'navigation_shortcuts',
            'navigation_menu',
        ];
        if (in_array($base_plugin_id, $allow_in_navigation, TRUE)) {
            $definition['allow_in_navigation'] = TRUE;
        }
        // Hide Navigation specific blocks from the generic UI.
        $hidden = [
            'navigation_user',
            'navigation_shortcuts',
            'navigation_menu',
            'navigation_link',
        ];
        if (in_array($base_plugin_id, $hidden, TRUE)) {
            $definition['_block_ui_hidden'] = TRUE;
        }
    });
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.