You are here

protected function TermFieldAutocomplete::getTermFieldVocabularies in GraphQL 8.4

Gets the vocabularies configured for given field if it is a term field.

Parameters

string $entity_type: Entity type of the field to get the vocabularies for.

string $bundle: Bundle of entity type of the field to get the vocabularies for.

string $field: Field name to get the vocabularies for.

Return value

string[] Vocabularies configured for the field in case it is a term field, null otherwise.

1 call to TermFieldAutocomplete::getTermFieldVocabularies()
TermFieldAutocomplete::resolve in src/Plugin/GraphQL/DataProducer/Taxonomy/TermFieldAutocomplete.php
Gets term items matched against given query for given vocabulary.

File

src/Plugin/GraphQL/DataProducer/Taxonomy/TermFieldAutocomplete.php, line 223

Class

TermFieldAutocomplete
Gets term items matching the given string in given field's vocabularies.

Namespace

Drupal\graphql\Plugin\GraphQL\DataProducer\Taxonomy

Code

protected function getTermFieldVocabularies(string $entity_type, string $bundle, string $field) : ?array {

  // Load field config of given entity type of given bundle. If not obtained,
  // bail out.
  if (!($field_config = $this
    ->getFieldConfig($entity_type, $bundle, $field))) {
    return NULL;
  }

  // Make sure the field is configured for taxonomy terms.
  $field_storage_config = $field_config
    ->getFieldStorageDefinition();
  if (!$this
    ->isTermFieldStorageConfig($field_storage_config)) {
    return NULL;
  }

  // Make sure that target vocabularies are configured.
  $handler_settings = $field_config
    ->getSetting('handler_settings');
  if (empty($handler_settings['target_bundles'])) {
    return NULL;
  }

  // Return list of vocabularies.
  return $handler_settings['target_bundles'];
}