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