You are here

public function HttpPurgerFormBase::buildFormTokensHelp in Generic HTTP Purger 8

Build the 'tokens' section of the form.

@todo This implementation depends on purge_tokens_token_info(), provided by the purge_token submodule. I'm aware this isn't the cleanest pattern but the most sensible way I can think of to get the supported token patterns.

Parameters

array $form: An associative array containing the structure of the form.

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

\Drupal\purge_purger_http\Entity\HttpPurgerSettings $settings: Configuration entity for the purger being configured.

1 call to HttpPurgerFormBase::buildFormTokensHelp()
HttpPurgerFormBase::buildForm in src/Form/HttpPurgerFormBase.php
Form constructor.

File

src/Form/HttpPurgerFormBase.php, line 452

Class

HttpPurgerFormBase
Abstract form base for HTTP based configurable purgers.

Namespace

Drupal\purge_purger_http\Form

Code

public function buildFormTokensHelp(array &$form, FormStateInterface $form_state, HttpPurgerSettings $settings) {
  if (function_exists('purge_tokens_token_info')) {
    $form['tokens'] = [
      '#type' => 'details',
      '#group' => 'tabs',
      '#title' => $this
        ->t('Tokens'),
      '#description' => $this
        ->t('<p>Tokens are replaced for the <b>Path</b>, <b>Body payload</b> and header <b>Value</b> fields.</p>'),
    ];
    $form['tokens']['table'] = [
      '#type' => 'table',
      '#responsive' => TRUE,
      '#header' => [
        'token' => [
          'data' => $this
            ->t('Token'),
          'class' => [
            RESPONSIVE_PRIORITY_MEDIUM,
          ],
        ],
        'description' => [
          'data' => $this
            ->t('Description'),
          'class' => [
            RESPONSIVE_PRIORITY_LOW,
          ],
        ],
      ],
    ];
    $tokens = purge_tokens_token_info()['tokens'];
    foreach ($this->tokenGroups as $token_group) {
      foreach ($tokens[$token_group] as $token => $info) {
        $token = sprintf('[%s:%s]', $token_group, $token);
        $form['tokens']['table'][$token]['token'] = [
          '#markup' => $this
            ->t('<b>@name</b><br /><code>@token</code>', [
            '@token' => $token,
            '@name' => $info['name'],
          ]),
        ];
        $form['tokens']['table'][$token]['description'] = [
          '#markup' => $info['description'],
        ];
      }
    }
  }
}