Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Entity.php
index 95e85e21a4209b559d5fa56dc4cefbb2d1cfb2eb..4fe37866f13570c88807c7860a7f030e719ecbe9 100644 (file)
@@ -88,6 +88,15 @@ abstract class Entity implements EntityInterface {
     return \Drupal::entityTypeManager();
   }
 
+  /**
+   * Gets the entity type bundle info service.
+   *
+   * @return \Drupal\Core\Entity\EntityTypeBundleInfoInterface
+   */
+  protected function entityTypeBundleInfo() {
+    return \Drupal::service('entity_type.bundle.info');
+  }
+
   /**
    * Gets the language manager.
    *
@@ -198,7 +207,7 @@ abstract class Entity implements EntityInterface {
       $bundle = $this->bundle();
       // A bundle-specific callback takes precedence over the generic one for
       // the entity type.
-      $bundles = $this->entityManager()->getBundleInfo($this->getEntityTypeId());
+      $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->getEntityTypeId());
       if (isset($bundles[$bundle]['uri_callback'])) {
         $uri_callback = $bundles[$bundle]['uri_callback'];
       }
@@ -344,11 +353,11 @@ abstract class Entity implements EntityInterface {
    */
   public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {
     if ($operation == 'create') {
-      return $this->entityManager()
+      return $this->entityTypeManager()
         ->getAccessControlHandler($this->entityTypeId)
         ->createAccess($this->bundle(), $account, [], $return_as_object);
     }
-    return $this->entityManager()
+    return $this->entityTypeManager()
       ->getAccessControlHandler($this->entityTypeId)
       ->access($this, $operation, $account, $return_as_object);
   }
@@ -374,7 +383,8 @@ abstract class Entity implements EntityInterface {
    * {@inheritdoc}
    */
   public function save() {
-    return $this->entityManager()->getStorage($this->entityTypeId)->save($this);
+    $storage = $this->entityTypeManager()->getStorage($this->entityTypeId);
+    return $storage->save($this);
   }
 
   /**
@@ -382,7 +392,7 @@ abstract class Entity implements EntityInterface {
    */
   public function delete() {
     if (!$this->isNew()) {
-      $this->entityManager()->getStorage($this->entityTypeId)->delete([$this->id() => $this]);
+      $this->entityTypeManager()->getStorage($this->entityTypeId)->delete([$this->id() => $this]);
     }
   }
 
@@ -407,7 +417,7 @@ abstract class Entity implements EntityInterface {
    * {@inheritdoc}
    */
   public function getEntityType() {
-    return $this->entityManager()->getDefinition($this->getEntityTypeId());
+    return $this->entityTypeManager()->getDefinition($this->getEntityTypeId());
   }
 
   /**
@@ -508,24 +518,30 @@ abstract class Entity implements EntityInterface {
    * {@inheritdoc}
    */
   public static function load($id) {
-    $entity_manager = \Drupal::entityManager();
-    return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->load($id);
+    $entity_type_repository = \Drupal::service('entity_type.repository');
+    $entity_type_manager = \Drupal::entityTypeManager();
+    $storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
+    return $storage->load($id);
   }
 
   /**
    * {@inheritdoc}
    */
   public static function loadMultiple(array $ids = NULL) {
-    $entity_manager = \Drupal::entityManager();
-    return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->loadMultiple($ids);
+    $entity_type_repository = \Drupal::service('entity_type.repository');
+    $entity_type_manager = \Drupal::entityTypeManager();
+    $storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
+    return $storage->loadMultiple($ids);
   }
 
   /**
    * {@inheritdoc}
    */
   public static function create(array $values = []) {
-    $entity_manager = \Drupal::entityManager();
-    return $entity_manager->getStorage($entity_manager->getEntityTypeFromClass(get_called_class()))->create($values);
+    $entity_type_repository = \Drupal::service('entity_type.repository');
+    $entity_type_manager = \Drupal::entityTypeManager();
+    $storage = $entity_type_manager->getStorage($entity_type_repository->getEntityTypeFromClass(get_called_class()));
+    return $storage->create($values);
   }
 
   /**