Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity / src / BundlePlugin / BundlePluginHandler.php
1 <?php
2
3 namespace Drupal\entity\BundlePlugin;
4
5 use Drupal\Component\Plugin\PluginManagerInterface;
6 use Drupal\Core\Entity\EntityTypeInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 class BundlePluginHandler implements BundlePluginHandlerInterface {
10
11   /**
12    * The entity type.
13    *
14    * @var \Drupal\Core\Entity\EntityTypeInterface
15    */
16   protected $entityType;
17
18   /**
19    * The bundle plugin manager.
20    *
21    * @var \Drupal\Component\Plugin\PluginManagerInterface
22    */
23   protected $pluginManager;
24
25   /**
26    * Constructs a new BundlePluginHandler object.
27    *
28    * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
29    *   The entity type.
30    * @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
31    *   The bundle plugin manager.
32    */
33   public function __construct(EntityTypeInterface $entity_type, PluginManagerInterface $plugin_manager) {
34     $this->entityType = $entity_type;
35     $this->pluginManager = $plugin_manager;
36   }
37
38   /**
39    * {@inheritdoc}
40    */
41   public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
42     return new static(
43       $entity_type,
44       $container->get('plugin.manager.' . $entity_type->get('bundle_plugin_type'))
45     );
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public function getBundleInfo() {
52     $bundles = [];
53     foreach ($this->pluginManager->getDefinitions() as $plugin_id => $definition) {
54       $bundles[$plugin_id] = [
55         'label' => $definition['label'],
56         'description' => isset($definition['description']) ? $definition['description'] : '',
57         'translatable' => $this->entityType->isTranslatable(),
58         'provider' => $definition['provider'],
59       ];
60     }
61     return $bundles;
62   }
63
64   /**
65    * {@inheritdoc}
66    */
67   public function getFieldStorageDefinitions() {
68     $definitions = [];
69     foreach (array_keys($this->pluginManager->getDefinitions()) as $plugin_id) {
70       /** @var \Drupal\entity\BundlePlugin\BundlePluginInterface $plugin */
71       $plugin = $this->pluginManager->createInstance($plugin_id);
72       $definitions += $plugin->buildFieldDefinitions();
73     }
74     // Ensure the presence of required keys which aren't set by the plugin.
75     foreach ($definitions as $field_name => $definition) {
76       $definition->setName($field_name);
77       $definition->setTargetEntityTypeId($this->entityType->id());
78       $definitions[$field_name] = $definition;
79     }
80
81     return $definitions;
82   }
83
84   /**
85    * {@inheritdoc}
86    */
87   public function getFieldDefinitions($bundle) {
88     /** @var \Drupal\entity\BundlePlugin\BundlePluginInterface $plugin */
89     $plugin = $this->pluginManager->createInstance($bundle);
90     $definitions = $plugin->buildFieldDefinitions();
91     // Ensure the presence of required keys which aren't set by the plugin.
92     foreach ($definitions as $field_name => $definition) {
93       $definition->setName($field_name);
94       $definition->setTargetEntityTypeId($this->entityType->id());
95       $definition->setTargetBundle($bundle);
96       $definitions[$field_name] = $definition;
97     }
98
99     return $definitions;
100   }
101
102 }