class StringListField in Drupal 10
Same name and namespace in other branches
- 8 core/modules/options/src/Plugin/views/argument/StringListField.php \Drupal\options\Plugin\views\argument\StringListField
- 9 core/modules/options/src/Plugin/views/argument/StringListField.php \Drupal\options\Plugin\views\argument\StringListField
Argument handler for list field to show the human readable name in summary.
Plugin annotation
@ViewsArgument("string_list_field");
Hierarchy
- class \Drupal\options\Plugin\views\argument\StringListField extends \Drupal\views\Plugin\views\argument\StringArgument uses FieldAPIHandlerTrait
Expanded class hierarchy of StringListField
File
- core/
modules/ options/ src/ Plugin/ views/ argument/ StringListField.php, line 19
Namespace
Drupal\options\Plugin\views\argumentView source
class StringListField extends StringArgument {
use FieldAPIHandlerTrait;
/**
* Stores the allowed values of this field.
*
* @var array
*/
protected $allowedValues = NULL;
/**
* {@inheritdoc}
*/
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);
}
/**
* {@inheritdoc}
*/
protected function defineOptions() {
$options = parent::defineOptions();
$options['summary']['contains']['human'] = [
'default' => FALSE,
];
return $options;
}
/**
* {@inheritdoc}
*/
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',
],
],
],
];
}
/**
* {@inheritdoc}
*/
public function summaryName($data) {
$value = $data->{$this->name_alias};
// If the list element has a human readable name show it.
if (isset($this->allowedValues[$value]) && !empty($this->options['summary']['human'])) {
$value = $this->allowedValues[$value];
}
return FieldFilteredMarkup::create($this
->caseTransform($value, $this->options['case']));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FieldAPIHandlerTrait:: |
protected | property | The entity field manager. | |
FieldAPIHandlerTrait:: |
protected | property | The field definition. | |
FieldAPIHandlerTrait:: |
protected | property | The field storage definition. | |
FieldAPIHandlerTrait:: |
protected | function | Returns the entity field manager. | |
FieldAPIHandlerTrait:: |
protected | function | Gets the field definition. | |
FieldAPIHandlerTrait:: |
protected | function | Gets the field storage configuration. | |
StringListField:: |
protected | property | Stores the allowed values of this field. | |
StringListField:: |
public | function | ||
StringListField:: |
protected | function | ||
StringListField:: |
public | function | ||
StringListField:: |
public | function |