class TypedDataPropertyDeriverBase
Same name in other branches
- 4.0.x src/Plugin/Deriver/TypedDataPropertyDeriverBase.php \Drupal\ctools\Plugin\Deriver\TypedDataPropertyDeriverBase
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements \Drupal\Component\Plugin\Derivative\DeriverInterface
- class \Drupal\ctools\Plugin\Deriver\TypedDataPropertyDeriverBase extends \Drupal\Component\Plugin\Derivative\DeriverBase implements \Drupal\Core\Plugin\Discovery\ContainerDeriverInterface uses \Drupal\Core\StringTranslation\StringTranslationTrait
Expanded class hierarchy of TypedDataPropertyDeriverBase
File
-
src/
Plugin/ Deriver/ TypedDataPropertyDeriverBase.php, line 21
Namespace
Drupal\ctools\Plugin\DeriverView source
abstract class TypedDataPropertyDeriverBase extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* @var \Drupal\Core\TypedData\TypedDataManagerInterface
*/
protected $typedDataManager;
/**
* The label string for use with derivative labels.
*
* @var string
*/
protected $label = '@property from @base';
/**
* TypedDataPropertyDeriverBase constructor.
*
* @param \Drupal\Core\TypedData\TypedDataManagerInterface $typed_data_manager
* The typed data manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(TypedDataManagerInterface $typed_data_manager, TranslationInterface $string_translation) {
$this->typedDataManager = $typed_data_manager;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container->get('typed_data_manager'), $container->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->typedDataManager
->getDefinitions() as $data_type_id => $data_type_definition) {
if (is_subclass_of($data_type_definition['class'], ComplexDataInterface::class, TRUE)) {
/** @var \Drupal\Core\TypedData\ComplexDataDefinitionInterface $base_definition */
$base_definition = $this->typedDataManager
->createDataDefinition($data_type_id);
foreach ($base_definition->getPropertyDefinitions() as $property_name => $property_definition) {
if ($property_definition instanceof BaseFieldDefinition || $property_definition instanceof FieldConfig) {
$this->generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, $base_definition, $property_name, $property_definition);
}
}
}
}
return $this->derivatives;
}
/**
* @param $property_definition
*
* @return mixed
*/
protected function getDataType($property_definition) {
if ($property_definition instanceof DataReferenceDefinitionInterface) {
return $property_definition->getTargetDefinition()
->getDataType();
}
if ($property_definition instanceof ListDataDefinitionInterface) {
return $property_definition->getItemDefinition()
->getDataType();
}
return $property_definition->getDataType();
}
/**
* Generates and maintains a derivative definition.
*
* This method should directly manipulate $this->derivatives and not return
* values. This allows implementations control over the derivative names.
*
* @param $base_plugin_definition
* The base plugin definition.
* @param string $data_type_id
* The plugin id of the data type.
* @param mixed $data_type_definition
* The plugin definition of the data type.
* @param \Drupal\Core\TypedData\DataDefinitionInterface $base_definition
* The data type definition of a complex data object.
* @param string $property_name
* The name of the property.
* @param \Drupal\Core\TypedData\DataDefinitionInterface $property_definition
* The property definition.
*/
protected abstract function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition);
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
DeriverBase::$derivatives | protected | property | List of derivative definitions. | 1 | |
DeriverBase::getDerivativeDefinition | public | function | Gets the definition of a derivative plugin. | Overrides DeriverInterface::getDerivativeDefinition | |
StringTranslationTrait::$stringTranslation | protected | property | The string translation service. | 3 | |
StringTranslationTrait::formatPlural | protected | function | Formats a string containing a count of items. | ||
StringTranslationTrait::getNumberOfPlurals | protected | function | Returns the number of plurals supported by a given language. | ||
StringTranslationTrait::getStringTranslation | protected | function | Gets the string translation service. | ||
StringTranslationTrait::setStringTranslation | public | function | Sets the string translation service to use. | 2 | |
StringTranslationTrait::t | protected | function | Translates a string to the current language or to a given language. | ||
TypedDataPropertyDeriverBase::$label | protected | property | The label string for use with derivative labels. | 2 | |
TypedDataPropertyDeriverBase::$typedDataManager | protected | property | |||
TypedDataPropertyDeriverBase::create | public static | function | Creates a new class instance. | Overrides ContainerDeriverInterface::create | |
TypedDataPropertyDeriverBase::generateDerivativeDefinition | abstract protected | function | Generates and maintains a derivative definition. | 1 | |
TypedDataPropertyDeriverBase::getDataType | protected | function | |||
TypedDataPropertyDeriverBase::getDerivativeDefinitions | public | function | Gets the definition of all derivatives of a base plugin. | Overrides DeriverBase::getDerivativeDefinitions | 1 |
TypedDataPropertyDeriverBase::__construct | public | function | TypedDataPropertyDeriverBase constructor. |