Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / layout_builder / src / Plugin / Derivative / InlineBlockDeriver.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 Symfony\Component\DependencyInjection\ContainerInterface;
9
10 /**
11  * Provides inline block plugin definitions for all custom block types.
12  *
13  * @internal
14  */
15 class InlineBlockDeriver extends DeriverBase implements ContainerDeriverInterface {
16
17   /**
18    * The entity type manager.
19    *
20    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
21    */
22   protected $entityTypeManager;
23
24   /**
25    * Constructs a BlockContentDeriver object.
26    *
27    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
28    *   The entity type manager.
29    */
30   public function __construct(EntityTypeManagerInterface $entity_type_manager) {
31     $this->entityTypeManager = $entity_type_manager;
32   }
33
34   /**
35    * {@inheritdoc}
36    */
37   public static function create(ContainerInterface $container, $base_plugin_id) {
38     return new static(
39       $container->get('entity_type.manager')
40     );
41   }
42
43   /**
44    * {@inheritdoc}
45    */
46   public function getDerivativeDefinitions($base_plugin_definition) {
47     $this->derivatives = [];
48     if ($this->entityTypeManager->hasDefinition('block_content_type')) {
49       $block_content_types = $this->entityTypeManager->getStorage('block_content_type')->loadMultiple();
50       foreach ($block_content_types as $id => $type) {
51         $this->derivatives[$id] = $base_plugin_definition;
52         $this->derivatives[$id]['admin_label'] = $type->label();
53         $this->derivatives[$id]['config_dependencies'][$type->getConfigDependencyKey()][] = $type->getConfigDependencyName();
54       }
55     }
56     return parent::getDerivativeDefinitions($base_plugin_definition);
57   }
58
59 }