diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php index 5848fb1..f030f95 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php @@ -3,6 +3,7 @@ namespace Drupal\Core\Entity\Plugin\DataType\Deriver; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeBundleInfo; use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -33,6 +34,13 @@ class EntityDeriver implements ContainerDeriverInterface { protected $entityManager; /** + * The bundle info service. + * + * @var \Drupal\Core\Entity\EntityTypeBundleInfo + */ + protected $bundleInfoService; + + /** * Constructs an EntityDeriver object. * * @param string $base_plugin_id @@ -40,9 +48,10 @@ class EntityDeriver implements ContainerDeriverInterface { * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager * The entity manager. */ - public function __construct($base_plugin_id, EntityManagerInterface $entity_manager) { + public function __construct($base_plugin_id, EntityManagerInterface $entity_manager, EntityTypeBundleInfo $bundle_info_service) { $this->basePluginId = $base_plugin_id; $this->entityManager = $entity_manager; + $this->bundleInfoService = $bundle_info_service; } /** @@ -51,7 +60,8 @@ public function __construct($base_plugin_id, EntityManagerInterface $entity_mana public static function create(ContainerInterface $container, $base_plugin_id) { return new static( $base_plugin_id, - $container->get('entity.manager') + $container->get('entity.manager'), + $container->get('entity_type.bundle.info') ); } @@ -75,7 +85,6 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Also keep the 'entity' defined as is. $this->derivatives[''] = $base_plugin_definition; // Add definitions for each entity type and bundle. - $bundle_info_service = \Drupal::service('entity_type.bundle.info'); foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { $this->derivatives[$entity_type_id] = array( 'label' => $entity_type->getLabel(), @@ -83,7 +92,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { ) + $base_plugin_definition; // Incorporate the bundles as entity:$entity_type:$bundle, if any. - foreach ($bundle_info_service->getBundleInfo($entity_type_id) as $bundle => $bundle_info) { + foreach ($this->bundleInfoService->getBundleInfo($entity_type_id) as $bundle => $bundle_info) { if ($bundle !== $entity_type_id) { $this->derivatives[$entity_type_id . ':' . $bundle] = array( 'label' => $bundle_info['label'],