"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.1.0-rc1/core/modules/layout_builder/src/Plugin/Derivative/LayoutBuilderLocalTaskDeriver.php" (18 Nov 2020, 2492 Bytes) of package /linux/www/drupal-9.1.0-rc1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "LayoutBuilderLocalTaskDeriver.php" see the Fossies "Dox" file reference documentation.

    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  *   Plugin derivers are internal.
   20  */
   21 class LayoutBuilderLocalTaskDeriver extends DeriverBase implements ContainerDeriverInterface {
   22 
   23   use StringTranslationTrait;
   24 
   25   /**
   26    * The entity type manager.
   27    *
   28    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   29    */
   30   protected $entityTypeManager;
   31 
   32   /**
   33    * The section storage manager.
   34    *
   35    * @var \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface
   36    */
   37   protected $sectionStorageManager;
   38 
   39   /**
   40    * Constructs a new LayoutBuilderLocalTaskDeriver.
   41    *
   42    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   43    *   The entity type manager.
   44    * @param \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface $section_storage_manager
   45    *   The section storage manager.
   46    */
   47   public function __construct(EntityTypeManagerInterface $entity_type_manager, SectionStorageManagerInterface $section_storage_manager) {
   48     $this->entityTypeManager = $entity_type_manager;
   49     $this->sectionStorageManager = $section_storage_manager;
   50   }
   51 
   52   /**
   53    * {@inheritdoc}
   54    */
   55   public static function create(ContainerInterface $container, $base_plugin_id) {
   56     return new static(
   57       $container->get('entity_type.manager'),
   58       $container->get('plugin.manager.layout_builder.section_storage')
   59     );
   60   }
   61 
   62   /**
   63    * {@inheritdoc}
   64    */
   65   public function getDerivativeDefinitions($base_plugin_definition) {
   66     foreach ($this->sectionStorageManager->getDefinitions() as $plugin_id => $definition) {
   67       $section_storage = $this->sectionStorageManager->loadEmpty($plugin_id);
   68       if ($section_storage instanceof SectionStorageLocalTaskProviderInterface) {
   69         $this->derivatives += $section_storage->buildLocalTasks($base_plugin_definition);
   70       }
   71     }
   72     return $this->derivatives;
   73   }
   74 
   75 }