You are here

public function PluginBase::globalTokenForm in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/src/Plugin/views/PluginBase.php \Drupal\views\Plugin\views\PluginBase::globalTokenForm()

Adds elements for available core tokens to a form.

Parameters

array $form: The form array to alter, passed by reference.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ViewsPluginInterface::globalTokenForm

3 calls to PluginBase::globalTokenForm()
TestExample::buildOptionsForm in core/modules/views/tests/modules/views_test_data/src/Plugin/views/area/TestExample.php
Provide a form to edit options for this plugin.
Title::buildOptionsForm in core/modules/views/src/Plugin/views/area/Title.php
Provide a form to edit options for this plugin.
TokenizeAreaPluginBase::tokenForm in core/modules/views/src/Plugin/views/area/TokenizeAreaPluginBase.php
Adds tokenization form elements.

File

core/modules/views/src/Plugin/views/PluginBase.php, line 453

Class

PluginBase
Base class for any views plugin types.

Namespace

Drupal\views\Plugin\views

Code

public function globalTokenForm(&$form, FormStateInterface $form_state) {
  $token_items = [];
  foreach ($this
    ->getAvailableGlobalTokens() as $type => $tokens) {
    $item = [
      '#markup' => $type,
      'children' => [],
    ];
    foreach ($tokens as $name => $info) {
      $item['children'][$name] = "[{$type}:{$name}]" . ' - ' . $info['name'] . ': ' . $info['description'];
    }
    $token_items[$type] = $item;
  }
  $form['global_tokens'] = [
    '#type' => 'details',
    '#title' => $this
      ->t('Available global token replacements'),
  ];
  $form['global_tokens']['list'] = [
    '#theme' => 'item_list',
    '#items' => $token_items,
    '#attributes' => [
      'class' => [
        'global-tokens',
      ],
    ],
  ];
}