TermNameAsId.php in Views taxonomy term name into ID 8
File
src/Plugin/views/argument_validator/TermNameAsId.php
View source
<?php
namespace Drupal\views_taxonomy_term_name_into_id\Plugin\views\argument_validator;
use Drupal\taxonomy\Plugin\views\argument_validator\TermName;
class TermNameAsId extends TermName {
public function validateArgument($argument) {
if ($this->options['transform']) {
$argument = str_replace('-', ' ', $argument);
}
if (!empty($this->options['bundles'])) {
$terms = $this->termStorage
->loadByProperties([
'name' => $argument,
'vid' => $this->options['bundles'],
]);
}
else {
$terms = $this->termStorage
->loadByProperties([
'name' => $argument,
]);
}
foreach ($terms as $term) {
if ($this
->validateEntity($term)) {
$this->argument->argument = $term
->id();
return TRUE;
}
}
return FALSE;
}
}
Classes
Name |
Description |
TermNameAsId |
Validates an argument as a term name and converts it to the term ID. |