Pull merge.
[yaffs-website] / web / core / modules / layout_builder / src / Plugin / Derivative / LayoutBuilderLocalTaskDeriver.php
1 <?php
2
3 namespace Drupal\layout_builder\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Drupal\layout_builder\Plugin\SectionStorage\SectionStorageLocalTaskProviderInterface;
10 use Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface;
11 use Symfony\Component\DependencyInjection\ContainerInterface;
12
13 /**
14  * Provides local task definitions for the layout builder user interface.
15  *
16  * @todo Remove this in https://www.drupal.org/project/drupal/issues/2936655.
17  *
18  * @internal
19  */
20 class LayoutBuilderLocalTaskDeriver extends DeriverBase implements ContainerDeriverInterface {
21
22   use StringTranslationTrait;
23
24   /**
25    * The entity type manager.
26    *
27    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
28    */
29   protected $entityTypeManager;
30
31   /**
32    * The section storage manager.
33    *
34    * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
35    */
36   protected $sectionStorageManager;
37
38   /**
39    * Constructs a new LayoutBuilderLocalTaskDeriver.
40    *
41    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
42    *   The entity type manager.
43    * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
44    *   The section storage manager.
45    */
46   public function __construct(EntityTypeManagerInterface $entity_type_manager, SectionStorageManagerInterface $section_storage_manager) {
47     $this->entityTypeManager = $entity_type_manager;
48     $this->sectionStorageManager = $section_storage_manager;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public static function create(ContainerInterface $container, $base_plugin_id) {
55     return new static(
56       $container->get('entity_type.manager'),
57       $container->get('plugin.manager.layout_builder.section_storage')
58     );
59   }
60
61   /**
62    * {@inheritdoc}
63    */
64   public function getDerivativeDefinitions($base_plugin_definition) {
65     foreach ($this->sectionStorageManager->getDefinitions() as $plugin_id => $definition) {
66       $section_storage = $this->sectionStorageManager->loadEmpty($plugin_id);
67       if ($section_storage instanceof SectionStorageLocalTaskProviderInterface) {
68         $this->derivatives += $section_storage->buildLocalTasks($base_plugin_definition);
69       }
70     }
71     return $this->derivatives;
72   }
73
74 }