You are here

public function TermName::validateArgument in Drupal 8

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

Performs validation for a given argument.

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;
  }
  $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;
}