You are here

public function EntitiesWithTerm::resolve in Thunder 6.2.x

Build entity query for entities, that reference a specific term.

Parameters

\Drupal\taxonomy\TermInterface $term: The term entity interface.

string $type: Entity type.

string[] $bundles: List of bundles to be filtered.

string $field: The term reference field of the bundle.

int $offset: Query only entities owned by current user.

int $limit: Maximum number of queried entities.

string[] $languages: Languages for queried entities.

array $sortBy: List of sorts.

int $depth: The depth of children of the term.

\Drupal\graphql\GraphQL\Execution\FieldContext $cacheContext: The caching context related to the current field.

Return value

\Drupal\thunder_gqls\Wrappers\EntityListResponse Base entity list response.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

File

modules/thunder_gqls/src/Plugin/GraphQL/DataProducer/EntitiesWithTerm.php, line 99

Class

EntitiesWithTerm
The channel list producer class.

Namespace

Drupal\thunder_gqls\Plugin\GraphQL\DataProducer

Code

public function resolve(TermInterface $term, string $type, array $bundles, string $field, int $offset, int $limit, array $languages, array $sortBy, int $depth, FieldContext $cacheContext) : EntityListResponse {
  $termIds = [
    $term
      ->id(),
  ];
  if ($depth > 0) {
    $terms = $this->entityTypeManager
      ->getStorage('taxonomy_term')
      ->loadTree($term
      ->bundle(), $term
      ->id(), $depth);
    $termIds = array_merge($termIds, array_column($terms, 'tid'));
  }
  $conditions = [
    [
      'field' => $field,
      'value' => $termIds,
      'operator' => 'IN',
    ],
  ];
  $query = $this
    ->query($type, $bundles, $offset, $limit, $conditions, $languages, $sortBy, $cacheContext);
  return new EntityListResponse($query);
}