function TokenizeAreaPluginBase::tokenForm
Same name in other branches
- 9 core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::tokenForm()
- 8.9.x core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::tokenForm()
- 10 core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php \Drupal\views\Plugin\views\area\TokenizeAreaPluginBase::tokenForm()
Adds tokenization form elements.
1 call to TokenizeAreaPluginBase::tokenForm()
- TokenizeAreaPluginBase::buildOptionsForm in core/
modules/ views/ src/ Plugin/ views/ area/ TokenizeAreaPluginBase.php
File
-
core/
modules/ views/ src/ Plugin/ views/ area/ TokenizeAreaPluginBase.php, line 42
Class
- TokenizeAreaPluginBase
- Tokenized base class for area handlers.
Namespace
Drupal\views\Plugin\views\areaCode
public function tokenForm(&$form, FormStateInterface $form_state) {
$form['tokenize'] = [
'#type' => 'checkbox',
'#title' => $this->t('Use replacement tokens from the first row'),
'#default_value' => $this->options['tokenize'],
];
// Get a list of the available fields and arguments for token replacement.
$options = [];
$optgroup_arguments = (string) $this->t('Arguments');
$optgroup_fields = (string) $this->t('Fields');
foreach ($this->view->display_handler
->getHandlers('field') as $field => $handler) {
$options[$optgroup_fields]["{{ {$field} }}"] = $handler->adminLabel();
}
foreach ($this->view->display_handler
->getHandlers('argument') as $arg => $handler) {
$options[$optgroup_arguments]["{{ arguments.{$arg} }}"] = $this->t('@argument title', [
'@argument' => $handler->adminLabel(),
]);
$options[$optgroup_arguments]["{{ raw_arguments.{$arg} }}"] = $this->t('@argument input', [
'@argument' => $handler->adminLabel(),
]);
}
if (!empty($options)) {
$form['tokens'] = [
'#type' => 'details',
'#title' => $this->t('Replacement patterns'),
'#open' => TRUE,
'#id' => 'edit-options-token-help',
'#states' => [
'visible' => [
':input[name="options[tokenize]"]' => [
'checked' => TRUE,
],
],
],
];
$form['tokens']['help'] = [
'#markup' => '<p>' . $this->t('The following tokens are available. You may use Twig syntax in this field.') . '</p>',
];
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = [];
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$form['tokens'][$type]['tokens'] = [
'#theme' => 'item_list',
'#items' => $items,
];
}
}
$form['tokens']['html_help'] = [
'#markup' => '<p>' . $this->t('You may include the following allowed HTML tags with these "Replacement patterns": <code>@tags</code>', [
'@tags' => '<' . implode('> <', Xss::getAdminTagList()) . '>',
]) . '</p>',
];
}
$this->globalTokenForm($form, $form_state);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.