5da50271720ff24f4c45705c5e461fb1eb9dd208
[yaffs-website] / web / core / modules / system / src / Plugin / Derivative / SystemMenuBlock.php
1 <?php
2
3 namespace Drupal\system\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides block plugin definitions for custom menus.
12  *
13  * @see \Drupal\system\Plugin\Block\SystemMenuBlock
14  */
15 class SystemMenuBlock extends DeriverBase implements ContainerDeriverInterface {
16
17   /**
18    * The menu storage.
19    *
20    * @var \Drupal\Core\Entity\EntityStorageInterface
21    */
22   protected $menuStorage;
23
24   /**
25    * Constructs new SystemMenuBlock.
26    *
27    * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
28    *   The menu storage.
29    */
30   public function __construct(EntityStorageInterface $menu_storage) {
31     $this->menuStorage = $menu_storage;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container, $base_plugin_id) {
38     return new static(
39       $container->get('entity.manager')->getStorage('menu')
40     );
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getDerivativeDefinitions($base_plugin_definition) {
47     foreach ($this->menuStorage->loadMultiple() as $menu => $entity) {
48       $this->derivatives[$menu] = $base_plugin_definition;
49       $this->derivatives[$menu]['admin_label'] = $entity->label();
50       $this->derivatives[$menu]['config_dependencies']['config'] = [$entity->getConfigDependencyName()];
51     }
52     return $this->derivatives;
53   }
54
55 }