Issue #2047533 by damiankloip: Inject dependencies into FieldItemDeriver derivative class.
parent
b6f16486d6
commit
d238a401e5
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue