You are here

public function EntityByIdDeriver::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/EntityByIdDeriver.php, line 44

Class

EntityByIdDeriver

Namespace

Drupal\graphql_core\Plugin\Deriver\Fields

Code

public function getDerivativeDefinitions($basePluginDefinition) {
  foreach ($this->entityTypeManager
    ->getDefinitions() as $id => $type) {
    if ($type instanceof ContentEntityTypeInterface) {
      $derivative = [
        'name' => StringHelper::propCase($id, 'by', 'id'),
        'type' => "entity:{$id}",
        'description' => $this
          ->t("Loads '@type' entities by their id.", [
          '@type' => $type
            ->getLabel(),
        ]),
        'entity_type' => $id,
      ] + $basePluginDefinition;
      if ($type
        ->isTranslatable()) {
        $derivative['arguments']['language'] = [
          'type' => 'LanguageId',
        ];
      }
      $this->derivatives["entity:{$id}"] = $derivative;
    }
  }
  return parent::getDerivativeDefinitions($basePluginDefinition);
}