You are here

class ViewsMenuLink in Drupal 8

Same name in this branch
  1. 8 core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php \Drupal\views\Plugin\Derivative\ViewsMenuLink
  2. 8 core/modules/views/src/Plugin/Menu/ViewsMenuLink.php \Drupal\views\Plugin\Menu\ViewsMenuLink
Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php \Drupal\views\Plugin\Derivative\ViewsMenuLink

Provides menu links for Views.

Hierarchy

Expanded class hierarchy of ViewsMenuLink

See also

\Drupal\views\Plugin\Menu\ViewsMenuLink

1 string reference to 'ViewsMenuLink'
views.links.menu.yml in core/modules/views/views.links.menu.yml
core/modules/views/views.links.menu.yml

File

core/modules/views/src/Plugin/Derivative/ViewsMenuLink.php, line 17

Namespace

Drupal\views\Plugin\Derivative
View source
class ViewsMenuLink extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The view storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $viewStorage;

  /**
   * Constructs a \Drupal\views\Plugin\Derivative\ViewsLocalTask instance.
   *
   * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage
   *   The view storage.
   */
  public function __construct(EntityStorageInterface $view_storage) {
    $this->viewStorage = $view_storage;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager')
      ->getStorage('view'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $links = [];
    $views = Views::getApplicableViews('uses_menu_links');
    foreach ($views as $data) {
      list($view_id, $display_id) = $data;

      /** @var \Drupal\views\ViewExecutable $executable */
      $executable = $this->viewStorage
        ->load($view_id)
        ->getExecutable();
      $executable
        ->initDisplay();
      $display = $executable->displayHandlers
        ->get($display_id);
      if ($display instanceof DisplayMenuInterface && ($result = $display
        ->getMenuLinks())) {
        foreach ($result as $link_id => $link) {
          $links[$link_id] = $link + $base_plugin_definition;
        }
      }
    }
    return $links;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
ViewsMenuLink::$viewStorage protected property The view storage.
ViewsMenuLink::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ViewsMenuLink::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
ViewsMenuLink::__construct public function Constructs a \Drupal\views\Plugin\Derivative\ViewsLocalTask instance.