class SystemMenuBlock

Same name in this branch

Provides block plugin definitions for system menus.

Hierarchy

Expanded class hierarchy of SystemMenuBlock

See also

\Drupal\system\Plugin\block\block\SystemMenuBlock

1 file declares its use of SystemMenuBlock
MenuBlock.php in drupal/core/modules/menu/lib/Drupal/menu/Plugin/Derivative/MenuBlock.php
Contains \Drupal\menu\Plugin\Derivative\MenuBlock.

File

drupal/core/modules/system/lib/Drupal/system/Plugin/Derivative/SystemMenuBlock.php, line 17
Contains \Drupal\system\Plugin\Derivative\SystemMenuBlock.

Namespace

Drupal\system\Plugin\Derivative
View source
class SystemMenuBlock implements DerivativeInterface {

  /**
   * List of derivative definitions.
   *
   * @var array
   */
  protected $derivatives = array();

  /**
   * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinition().
   */
  public function getDerivativeDefinition($derivative_id, array $base_plugin_definition) {
    if (!empty($this->derivatives) && !empty($this->derivatives[$derivative_id])) {
      return $this->derivatives[$derivative_id];
    }
    $this
      ->getDerivativeDefinitions($base_plugin_definition);
    return $this->derivatives[$derivative_id];
  }

  /**
   * Implements \Drupal\Component\Plugin\Derivative\DerivativeInterface::getDerivativeDefinitions().
   */
  public function getDerivativeDefinitions(array $base_plugin_definition) {

    // Provide a block plugin definition for each system menu.
    foreach (menu_list_system_menus() as $menu => $name) {

      // The block deltas need to be prefixed with 'menu-', since the 'main'
      // menu would otherwise clash with the 'main' page content block.
      $menu_key = 'menu-' . $menu;
      $this->derivatives[$menu_key] = $base_plugin_definition;
      $this->derivatives[$menu_key]['delta'] = $menu_key;

      // It is possible that users changed the menu label. Fall back on the
      // built-in menu label if the entity was not found.
      $entity = entity_load('menu', $menu);
      $this->derivatives[$menu_key]['admin_label'] = !empty($entity) ? $entity
        ->label() : $name;
      $this->derivatives[$menu_key]['cache'] = DRUPAL_NO_CACHE;
    }
    return $this->derivatives;
  }

}

Members