Commit d238a401 authored by alexpott's avatar alexpott
Browse files

Issue #2047533 by damiankloip: Inject dependencies into FieldItemDeriver derivative class.

parent b6f16486
......@@ -7,12 +7,14 @@
namespace Drupal\Core\Entity\Plugin\DataType\Deriver;
use Drupal\Component\Plugin\Derivative\DerivativeInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDerivativeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides data type plugins for each existing field type plugin.
*/
class FieldItemDeriver implements DerivativeInterface {
class FieldItemDeriver implements ContainerDerivativeInterface {
/**
* List of derivative definitions.
......@@ -21,6 +23,43 @@ class FieldItemDeriver implements DerivativeInterface {
*/
protected $derivatives = array();
/**
* The base plugin ID this derivative is for.
*
* @var string
*/
protected $basePluginId;
/**
* The field type plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
*/
protected $fieldTypePluginManager;
/**
* Constructs a FieldItemDeriver object.
*
* @param string $base_plugin_id
* The base plugin ID.
* @param \Drupal\Component\Plugin\PluginManagerInterface $field_type_plugin_manager
* The field type plugin manager.
*/
public function __construct($base_plugin_id, PluginManagerInterface $field_type_plugin_manager) {
$this->basePluginId = $base_plugin_id;
$this->fieldTypePluginManager = $field_type_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$base_plugin_id,
$container->get('plugin.manager.entity.field.field_type')
);
}
/**
* {@inheritdoc}
*/
......@@ -37,7 +76,7 @@ public function getDerivativeDefinition($derivative_id, array $base_plugin_defin
* {@inheritdoc}
*/
public function getDerivativeDefinitions(array $base_plugin_definition) {
foreach (\Drupal::service('plugin.manager.entity.field.field_type')->getDefinitions() as $plugin_id => $definition) {
foreach ($this->fieldTypePluginManager->getDefinitions() as $plugin_id => $definition) {
$this->derivatives[$plugin_id] = $definition;
}
return $this->derivatives;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment