Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / views / src / Plugin / Derivative / ViewsMenuLink.php
1 <?php
2
3 namespace Drupal\views\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
7 use Drupal\views\Plugin\views\display\DisplayMenuInterface;
8 use Drupal\views\Views;
9 use Drupal\Core\Entity\EntityStorageInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Provides menu links for Views.
14  *
15  * @see \Drupal\views\Plugin\Menu\ViewsMenuLink
16  */
17 class ViewsMenuLink extends DeriverBase implements ContainerDeriverInterface {
18
19   /**
20    * The view storage.
21    *
22    * @var \Drupal\Core\Entity\EntityStorageInterface
23    */
24   protected $viewStorage;
25
26   /**
27    * Constructs a \Drupal\views\Plugin\Derivative\ViewsLocalTask instance.
28    *
29    * @param \Drupal\Core\Entity\EntityStorageInterface $view_storage
30    *   The view storage.
31    */
32   public function __construct(EntityStorageInterface $view_storage) {
33     $this->viewStorage = $view_storage;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public static function create(ContainerInterface $container, $base_plugin_id) {
40     return new static(
41       $container->get('entity.manager')->getStorage('view')
42     );
43   }
44
45   /**
46    * {@inheritdoc}
47    */
48   public function getDerivativeDefinitions($base_plugin_definition) {
49     $links = [];
50     $views = Views::getApplicableViews('uses_menu_links');
51
52     foreach ($views as $data) {
53       list($view_id, $display_id) = $data;
54       /** @var \Drupal\views\ViewExecutable $executable */
55       $executable = $this->viewStorage->load($view_id)->getExecutable();
56       $executable->initDisplay();
57       $display = $executable->displayHandlers->get($display_id);
58
59       if (($display instanceof DisplayMenuInterface) && ($result = $display->getMenuLinks())) {
60         foreach ($result as $link_id => $link) {
61           $links[$link_id] = $link + $base_plugin_definition;
62         }
63       }
64     }
65
66     return $links;
67   }
68
69 }