class TypedDataRelationshipDeriver in Chaos Tool Suite (ctools) 8.3
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\ctools\Plugin\Deriver\TypedDataPropertyDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\ctools\Plugin\Deriver\TypedDataRelationshipDeriver implements ContainerDeriverInterface
- class \Drupal\ctools\Plugin\Deriver\TypedDataPropertyDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of TypedDataRelationshipDeriver
File
- src/
Plugin/ Deriver/ TypedDataRelationshipDeriver.php, line 12
Namespace
Drupal\ctools\Plugin\DeriverView source
class TypedDataRelationshipDeriver extends TypedDataPropertyDeriverBase implements ContainerDeriverInterface {
/**
* {@inheritdoc}
*/
protected function generateDerivativeDefinition($base_plugin_definition, $data_type_id, $data_type_definition, DataDefinitionInterface $base_definition, $property_name, DataDefinitionInterface $property_definition) {
$bundle_info = $base_definition
->getConstraint('Bundle');
// Identify base definitions that appear on bundle-able entities.
if ($bundle_info && array_filter($bundle_info) && $base_definition
->getConstraint('EntityType')) {
$base_data_type = 'entity:' . $base_definition
->getConstraint('EntityType');
}
else {
$base_data_type = $data_type_id;
}
// If we've not processed this thing before.
if (!isset($this->derivatives[$base_data_type . ':' . $property_name])) {
$derivative = $base_plugin_definition;
$derivative['label'] = $this
->t($this->label, [
'@property' => $property_definition
->getLabel(),
'@base' => $data_type_definition['label'],
]);
$derivative['data_type'] = $property_definition
->getFieldStorageDefinition()
->getPropertyDefinition($property_definition
->getFieldStorageDefinition()
->getMainPropertyName())
->getDataType();
$derivative['property_name'] = $property_name;
if (strpos($base_data_type, 'entity:') === 0) {
$context_definition = new EntityContextDefinition($base_data_type, $this->typedDataManager
->createDataDefinition($base_data_type));
}
else {
$context_definition = new ContextDefinition($base_data_type, $this->typedDataManager
->createDataDefinition($base_data_type));
}
// Add the constraints of the base definition to the context definition.
if ($base_definition
->getConstraint('Bundle')) {
$context_definition
->addConstraint('Bundle', $base_definition
->getConstraint('Bundle'));
}
$derivative['context_definitions'] = [
'base' => $context_definition,
];
$derivative['property_name'] = $property_name;
$this->derivatives[$base_data_type . ':' . $property_name] = $derivative;
}
elseif ($property_definition instanceof FieldConfigInterface) {
// We should only end up in here on entity bundles.
$derivative = $this->derivatives[$base_data_type . ':' . $property_name];
// Update label.
/** @var \Drupal\Core\StringTranslation\TranslatableMarkup $label */
$label = $derivative['label'];
list(, , $argument_name) = explode(':', $data_type_id);
$arguments = $label
->getArguments();
$arguments['@' . $argument_name] = $data_type_definition['label'];
$string_args = $arguments;
array_shift($string_args);
$last = array_slice($string_args, -1);
// The slice doesn't remove, so do that now.
array_pop($string_args);
$string = count($string_args) >= 2 ? '@property from ' . implode(', ', array_keys($string_args)) . ' and ' . array_keys($last)[0] : '@property from @base and ' . array_keys($last)[0];
$this->derivatives[$base_data_type . ':' . $property_name]['label'] = $this
->t($string, $arguments);
if ($base_definition
->getConstraint('Bundle')) {
// Add bundle constraints.
$context_definition = $derivative['context_definitions']['base'];
$bundles = $context_definition
->getConstraint('Bundle') ?: [];
$bundles = array_merge($bundles, $base_definition
->getConstraint('Bundle'));
$context_definition
->addConstraint('Bundle', $bundles);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TypedDataPropertyDeriverBase:: |
protected | property | The label string for use with derivative labels. | 2 |
TypedDataPropertyDeriverBase:: |
protected | property | ||
TypedDataPropertyDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
TypedDataPropertyDeriverBase:: |
protected | function | ||
TypedDataPropertyDeriverBase:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
1 |
TypedDataPropertyDeriverBase:: |
public | function | TypedDataPropertyDeriverBase constructor. | |
TypedDataRelationshipDeriver:: |
protected | function |
Generates and maintains a derivative definition. Overrides TypedDataPropertyDeriverBase:: |
2 |