Issue #2046987 by damiankloip: Inject dependencies into EntityDeriver derivative class.

8.0.x
Alex Pott 2013-08-02 01:09:43 +02:00
parent b0c8255cba
commit c7a95535e7
1 changed files with 42 additions and 3 deletions

View File

@ -7,12 +7,14 @@
namespace Drupal\Core\Entity\Plugin\DataType\Deriver;
use Drupal\Component\Plugin\Derivative\DerivativeInterface;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides data type plugins for each existing entity type and bundle.
*/
class EntityDeriver implements DerivativeInterface {
class EntityDeriver implements ContainerDerivativeInterface {
/**
* List of derivative definitions.
@ -21,6 +23,43 @@ class EntityDeriver implements DerivativeInterface {
*/
protected $derivatives = array();
/**
* The base plugin ID this derivative is for.
*
* @var string
*/
protected $basePluginId;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManager
*/
protected $entityManager;
/**
* Constructs an EntityDeriver object.
*
* @param string $base_plugin_id
* The base plugin ID.
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
*/
public function __construct($base_plugin_id, EntityManager $entity_manager) {
$this->basePluginId = $base_plugin_id;
$this->entityManager = $entity_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('plugin.manager.entity')
);
}
/**
* {@inheritdoc}
*/
@ -41,7 +80,7 @@ class EntityDeriver implements DerivativeInterface {
// Also keep the 'entity' defined as is.
$this->derivatives[''] = $base_plugin_definition;
// Add definitions for each entity type and bundle.
foreach (entity_get_info() as $entity_type => $info) {
foreach ($this->entityManager->getDefinitions() as $entity_type => $info) {
$this->derivatives[$entity_type] = array(
'label' => $info['label'],
'class' => $info['class'],