Upgraded imagemagick and manually altered pdf to image module to handle changes....
[yaffs-website] / web / modules / contrib / entity / src / BundlePlugin / BundlePluginInstaller.php
1 <?php
2
3 namespace Drupal\entity\BundlePlugin;
4
5 use Drupal\Core\Entity\EntityBundleListenerInterface;
6 use Drupal\Core\Entity\EntityTypeInterface;
7 use Drupal\Core\Entity\EntityTypeManagerInterface;
8 use Drupal\Core\Field\FieldDefinitionListenerInterface;
9 use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
10
11 class BundlePluginInstaller implements BundlePluginInstallerInterface {
12
13   /**
14    * The entity type manager.
15    *
16    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
17    */
18   protected $entityTypeManager;
19
20   /**
21    * The entity bundle listener.
22    *
23    * @var \Drupal\Core\Entity\EntityBundleListenerInterface
24    */
25   protected $entityBundleListener;
26
27   /**
28    * The field storage definition listener.
29    *
30    * @var \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
31    */
32   protected $fieldStorageDefinitionListener;
33
34   /**
35    * The field definition listener.
36    *
37    * @var \Drupal\Core\Field\FieldDefinitionListenerInterface
38    */
39   protected $fieldDefinitionListener;
40
41   /**
42    * Constructs a new BundlePluginInstaller object.
43    *
44    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
45    *   The entity type manager.
46    * @param \Drupal\Core\Entity\EntityBundleListenerInterface $entity_bundle_listener
47    *   The entity bundle listener.
48    * @param \Drupal\Core\Field\FieldStorageDefinitionListenerInterface $field_storage_definition_listener
49    *   The field storage definition listener.
50    * @param \Drupal\Core\Field\FieldDefinitionListenerInterface $field_definition_listener
51    *   The field definition listener.
52    */
53   public function __construct(EntityTypeManagerInterface $entity_type_manager, EntityBundleListenerInterface $entity_bundle_listener, FieldStorageDefinitionListenerInterface $field_storage_definition_listener, FieldDefinitionListenerInterface $field_definition_listener) {
54     $this->entityTypeManager = $entity_type_manager;
55     $this->entityBundleListener = $entity_bundle_listener;
56     $this->fieldStorageDefinitionListener = $field_storage_definition_listener;
57     $this->fieldDefinitionListener = $field_definition_listener;
58   }
59
60   /**
61    * {@inheritdoc}
62    */
63   public function installBundles(EntityTypeInterface $entity_type, array $modules) {
64     $bundle_handler = $this->entityTypeManager->getHandler($entity_type->id(), 'bundle_plugin');
65     $bundles = array_filter($bundle_handler->getBundleInfo(), function ($bundle_info) use ($modules) {
66       return in_array($bundle_info['provider'], $modules, TRUE);
67     });
68     foreach (array_keys($bundles) as $bundle) {
69       $this->entityBundleListener->onBundleCreate($bundle, $entity_type->id());
70       foreach ($bundle_handler->getFieldDefinitions($bundle) as $definition) {
71         $this->fieldStorageDefinitionListener->onFieldStorageDefinitionCreate($definition);
72         $this->fieldDefinitionListener->onFieldDefinitionCreate($definition);
73       }
74     }
75   }
76
77   /**
78    * {@inheritdoc}
79    */
80   public function uninstallBundles(EntityTypeInterface $entity_type, array $modules) {
81     $bundle_handler = $this->entityTypeManager->getHandler($entity_type->id(), 'bundle_plugin');
82     $bundles = array_filter($bundle_handler->getBundleInfo(), function ($bundle_info) use ($modules) {
83       return in_array($bundle_info['provider'], $modules, TRUE);
84     });
85     foreach (array_keys($bundles) as $bundle) {
86       $this->entityBundleListener->onBundleDelete($bundle, $entity_type->id());
87       foreach ($bundle_handler->getFieldDefinitions($bundle) as $definition) {
88         $this->fieldDefinitionListener->onFieldDefinitionDelete($definition);
89         $this->fieldStorageDefinitionListener->onFieldStorageDefinitionDelete($definition);
90       }
91     }
92   }
93
94 }