function TermName::validateArgument

Same name and namespace in other branches
  1. 11.x core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName::validateArgument()
  2. 10 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName::validateArgument()
  3. 9 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName::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;
  }
  $terms = $this->termStorage
    ->loadByProperties([
    'name' => $argument,
  ]);
  if (!$terms) {
    // Returned empty array no terms with the name.
    return FALSE;
  }
  // Not knowing which term will be used if more than one is returned check
  // each one.
  foreach ($terms as $term) {
    if (!$this->validateEntity($term)) {
      return FALSE;
    }
  }
  return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.