You are here

public function TermName::validateArgument in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName::validateArgument()
  2. 9 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName::validateArgument()

Overrides Entity::validateArgument

File

core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php, line 64

Class

TermName
Validates whether a term name is a valid term argument.

Namespace

Drupal\taxonomy\Plugin\views\argument_validator

Code

public function validateArgument($argument) {
  if ($this->options['transform']) {
    $argument = str_replace('-', ' ', $argument);
    $this->argument->argument = $argument;
  }

  // If bundles is set then restrict the loaded terms to the given bundles.
  if (!empty($this->options['bundles'])) {
    $terms = $this->termStorage
      ->loadByProperties([
      'name' => $argument,
      'vid' => $this->options['bundles'],
    ]);
  }
  else {
    $terms = $this->termStorage
      ->loadByProperties([
      'name' => $argument,
    ]);
  }

  // $terms are already bundle tested but we need to test access control.
  foreach ($terms as $term) {
    if ($this
      ->validateEntity($term)) {
      return TRUE;
    }
  }
  return FALSE;
}