StringListField.php in Drupal 8
File
core/modules/options/src/Plugin/views/argument/StringListField.php
View source
<?php
namespace Drupal\options\Plugin\views\argument;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\FieldAPIHandlerTrait;
use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\Plugin\views\argument\StringArgument;
class StringListField extends StringArgument {
use AllowedTagsXssTrait;
use FieldAPIHandlerTrait;
protected $allowedValues = NULL;
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$field_storage = $this
->getFieldStorageDefinition();
$this->allowedValues = options_allowed_values($field_storage);
}
protected function defineOptions() {
$options = parent::defineOptions();
$options['summary']['contains']['human'] = [
'default' => FALSE,
];
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['summary']['human'] = [
'#title' => $this
->t('Display list value as human readable'),
'#type' => 'checkbox',
'#default_value' => $this->options['summary']['human'],
'#states' => [
'visible' => [
':input[name="options[default_action]"]' => [
'value' => 'summary',
],
],
],
];
}
public function summaryName($data) {
$value = $data->{$this->name_alias};
if (isset($this->allowedValues[$value]) && !empty($this->options['summary']['human'])) {
$value = $this->allowedValues[$value];
}
return FieldFilteredMarkup::create($this
->caseTransform($value, $this->options['case']));
}
}
Classes
Name |
Description |
StringListField |
Argument handler for list field to show the human readable name in summary. |