diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/FieldItemDeriver.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/FieldItemDeriver.php index 2a304df2cb3..60b47f9a5c1 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/FieldItemDeriver.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/FieldItemDeriver.php @@ -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 @@ class FieldItemDeriver implements DerivativeInterface { * {@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;