public function EntityReferenceReverseDeriver::getDerivativeDefinitions in GraphQL 8.3
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
- modules/
graphql_core/ src/ Plugin/ Deriver/ Fields/ EntityReferenceReverseDeriver.php, line 73
Class
Namespace
Drupal\graphql_core\Plugin\Deriver\FieldsCode
public function getDerivativeDefinitions($basePluginDefinition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entityTypeId => $entityType) {
$interfaces = class_implements($entityType
->getClass());
if (!array_key_exists(FieldableEntityInterface::class, $interfaces)) {
continue;
}
foreach ($this->entityFieldManager
->getFieldStorageDefinitions($entityTypeId) as $fieldDefinition) {
if ($fieldDefinition
->getType() !== 'entity_reference' || !($targetTypeId = $fieldDefinition
->getSetting('target_type'))) {
continue;
}
$tags = array_merge($fieldDefinition
->getCacheTags(), [
'entity_field_info',
]);
$contexts = $fieldDefinition
->getCacheContexts();
$maxAge = $fieldDefinition
->getCacheMaxAge();
$fieldName = $fieldDefinition
->getName();
$derivative = [
'parents' => [
StringHelper::camelCase($targetTypeId),
],
'name' => StringHelper::propCase('reverse', $fieldName, $entityTypeId),
'description' => $this
->t('Reverse reference: @description', [
'@description' => $fieldDefinition
->getDescription(),
]),
'field' => $fieldName,
'entity_type' => $entityTypeId,
'schema_cache_tags' => $tags,
'schema_cache_contexts' => $contexts,
'schema_cache_max_age' => $maxAge,
] + $basePluginDefinition;
/** @var \Drupal\Core\Entity\TypedData\EntityDataDefinitionInterface $definition */
$this->derivatives["{$entityTypeId}-{$fieldName}"] = $derivative;
}
}
return $this->derivatives;
}