public function Field::getDerivativeDefinitions in Synonyms 8
Same name and namespace in other branches
- 2.0.x src/Plugin/Derivative/Field.php \Drupal\synonyms\Plugin\Derivative\Field::getDerivativeDefinitions()
Gets the definition of all derivatives of a base plugin.
Parameters
array $base_plugin_definition: The definition array of the base plugin.
Return value
array An array of full derivative definitions keyed on derivative id.
Overrides DeriverBase::getDerivativeDefinitions
See also
getDerivativeDefinition()
File
- src/
Plugin/ Derivative/ Field.php, line 85
Class
- Field
- Derivative for synonyms provider plugins.
Namespace
Drupal\synonyms\Plugin\DerivativeCode
public function getDerivativeDefinitions($base_plugin_definition) {
$field_type_to_property_map = $this->fieldTypeToSynonyms
->getSimpleFieldTypeToPropertyMap();
foreach ($this->behaviorService
->getBehaviorServices() as $service_id => $behavior) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type) {
if ($entity_type instanceof ContentEntityType) {
foreach ($this->entityTypeBundleInfo
->getBundleInfo($entity_type
->id()) as $bundle => $bundle_info) {
$base_fields = $this->entityFieldManager
->getBaseFieldDefinitions($entity_type
->id());
$fields = $this->entityFieldManager
->getFieldDefinitions($entity_type
->id(), $bundle);
switch ($base_plugin_definition['id']) {
case 'base_field':
$fields = $base_fields;
break;
case 'field':
$fields = array_diff_key($fields, $base_fields);
break;
}
foreach ($fields as $field) {
if ($field
->getName() != 'synonyms' && isset($field_type_to_property_map[$field
->getType()])) {
$derivative_name = implode('_', [
$service_id,
$entity_type
->id(),
$bundle,
$field
->getName(),
]);
$this->derivatives[$derivative_name] = $base_plugin_definition;
$this->derivatives[$derivative_name]['label'] = $this
->t('@behavior on @field', [
'@behavior' => $behavior['service']
->getTitle(),
'@field' => $field
->getLabel(),
]);
$this->derivatives[$derivative_name]['synonyms_behavior_service'] = $service_id;
$this->derivatives[$derivative_name]['controlled_entity_type'] = $entity_type
->id();
$this->derivatives[$derivative_name]['controlled_bundle'] = $bundle;
$this->derivatives[$derivative_name]['field'] = $field
->getName();
}
}
}
}
}
}
return $this->derivatives;
}