function TermName::validateArgument

Same name and namespace in other branches
  1. 8.9.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. 11.x 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;
}

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