class TermName
Same name in this branch
- 9 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName
Same name and namespace in other branches
- 11.x core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName
- 11.x core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName
- 10 core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName
- 10 core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName
- 8.9.x core/modules/taxonomy/src/Plugin/views/argument_validator/TermName.php \Drupal\taxonomy\Plugin\views\argument_validator\TermName
- 8.9.x core/modules/taxonomy/src/Plugin/views/field/TermName.php \Drupal\taxonomy\Plugin\views\field\TermName
Displays taxonomy term names and allows converting spaces to hyphens.
Plugin annotation
@ViewsField("term_name");
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\field\EntityField implements \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\views\Plugin\views\field\MultiItemsFieldHandlerInterface, \Drupal\views\Plugin\DependentWithRemovalPluginInterface uses \Drupal\views\FieldAPIHandlerTrait, \Drupal\Core\Plugin\PluginDependencyTrait extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\taxonomy\Plugin\views\field\TermName extends \Drupal\views\Plugin\views\field\EntityField
- class \Drupal\views\Plugin\views\field\EntityField implements \Drupal\Core\Cache\CacheableDependencyInterface, \Drupal\views\Plugin\views\field\MultiItemsFieldHandlerInterface, \Drupal\views\Plugin\DependentWithRemovalPluginInterface uses \Drupal\views\FieldAPIHandlerTrait, \Drupal\Core\Plugin\PluginDependencyTrait extends \Drupal\views\Plugin\views\field\FieldPluginBase
- class \Drupal\views\Plugin\views\field\FieldPluginBase implements \Drupal\views\Plugin\views\field\FieldHandlerInterface extends \Drupal\views\Plugin\views\HandlerBase
- class \Drupal\views\Plugin\views\HandlerBase implements \Drupal\views\Plugin\views\ViewsHandlerInterface extends \Drupal\views\Plugin\views\PluginBase
- class \Drupal\views\Plugin\views\PluginBase implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\views\Plugin\views\ViewsPluginInterface, \Drupal\Component\Plugin\DependentPluginInterface, \Drupal\Core\Security\TrustedCallbackInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of TermName
Related topics
File
-
core/
modules/ taxonomy/ src/ Plugin/ views/ field/ TermName.php, line 16
Namespace
Drupal\taxonomy\Plugin\views\fieldView source
class TermName extends EntityField {
/**
* {@inheritdoc}
*/
public function getItems(ResultRow $values) {
$items = parent::getItems($values);
if ($this->options['convert_spaces']) {
foreach ($items as &$item) {
// Replace spaces with hyphens.
$name = str_replace(' ', '-', $item['raw']->get('value')
->getValue());
empty($this->options['settings']['link_to_entity']) ? $item['rendered']['#context']['value'] = $name : $item['rendered']['#title']['#context']['value'] = $name;
}
}
return $items;
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['convert_spaces'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['convert_spaces'] = [
'#title' => $this->t('Convert spaces in term names to hyphens'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['convert_spaces']),
];
parent::buildOptionsForm($form, $form_state);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.