FieldItemDeriver.php in Drupal 10
File
core/lib/Drupal/Core/Field/Plugin/DataType/Deriver/FieldItemDeriver.php
View source
<?php
namespace Drupal\Core\Field\Plugin\DataType\Deriver;
use Drupal\Core\Field\FieldTypePluginManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FieldItemDeriver implements ContainerDeriverInterface {
protected $derivatives = [];
protected $basePluginId;
protected $fieldTypePluginManager;
public function __construct($base_plugin_id, FieldTypePluginManagerInterface $field_type_plugin_manager) {
$this->basePluginId = $base_plugin_id;
$this->fieldTypePluginManager = $field_type_plugin_manager;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('plugin.manager.field.field_type'));
}
public function getDerivativeDefinition($derivative_id, $base_plugin_definition) {
if (!isset($this->derivatives)) {
$this
->getDerivativeDefinitions($base_plugin_definition);
}
if (isset($this->derivatives[$derivative_id])) {
return $this->derivatives[$derivative_id];
}
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->fieldTypePluginManager
->getDefinitions() as $plugin_id => $definition) {
$definition['definition_class'] = '\\Drupal\\Core\\Field\\TypedData\\FieldItemDataDefinition';
$definition['list_definition_class'] = '\\Drupal\\Core\\Field\\BaseFieldDefinition';
$definition['unwrap_for_canonical_representation'] = FALSE;
$this->derivatives[$plugin_id] = $definition;
}
return $this->derivatives;
}
}