TermName.php in Zircon Profile 8
File
core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php
View source
<?php
namespace Drupal\taxonomy\Plugin\views\argument_validator;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\views\Plugin\views\argument_validator\Entity;
class TermName extends Entity {
protected $termStorage;
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_manager);
$this->multipleCapable = FALSE;
$this->termStorage = $entity_manager
->getStorage('taxonomy_term');
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['transform'] = array(
'default' => FALSE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['transform'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Transform dashes in URL to spaces in term name filter values'),
'#default_value' => $this->options['transform'],
);
}
public function validateArgument($argument) {
if ($this->options['transform']) {
$argument = str_replace('-', ' ', $argument);
}
$terms = $this->termStorage
->loadByProperties(array(
'name' => $argument,
));
if (!$terms) {
return FALSE;
}
foreach ($terms as $term) {
if (!$this
->validateEntity($term)) {
return FALSE;
}
}
return TRUE;
}
}
Classes
Name |
Description |
TermName |
Validates whether a term name is a valid term argument. |