3 namespace Drupal\layout_builder\Plugin\Derivative;
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;
14 * Provides local task definitions for the layout builder user interface.
16 * @todo Remove this in https://www.drupal.org/project/drupal/issues/2936655.
20 class LayoutBuilderLocalTaskDeriver extends DeriverBase implements ContainerDeriverInterface {
22 use StringTranslationTrait;
25 * The entity type manager.
27 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
29 protected $entityTypeManager;
32 * The section storage manager.
34 * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
36 protected $sectionStorageManager;
39 * Constructs a new LayoutBuilderLocalTaskDeriver.
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.
46 public function __construct(EntityTypeManagerInterface $entity_type_manager, SectionStorageManagerInterface $section_storage_manager) {
47 $this->entityTypeManager = $entity_type_manager;
48 $this->sectionStorageManager = $section_storage_manager;
54 public static function create(ContainerInterface $container, $base_plugin_id) {
56 $container->get('entity_type.manager'),
57 $container->get('plugin.manager.layout_builder.section_storage')
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);
71 return $this->derivatives;