public function VarnishPurgerFormBase::buildFormTokensHelp in Varnish purger 8
Same name and namespace in other branches
- 8.2 src/Form/VarnishPurgerFormBase.php \Drupal\varnish_purger\Form\VarnishPurgerFormBase::buildFormTokensHelp()
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\varnish_purger\Entity\VarnishPurgerSettings $settings: Configuration entity for the purger being configured.
1 call to VarnishPurgerFormBase::buildFormTokensHelp()
- VarnishPurgerFormBase::buildForm in src/
Form/ VarnishPurgerFormBase.php - Form constructor.
File
- src/
Form/ VarnishPurgerFormBase.php, line 376
Class
- VarnishPurgerFormBase
- Abstract form base for Varnish based configurable purgers.
Namespace
Drupal\varnish_purger\FormCode
public function buildFormTokensHelp(array &$form, FormStateInterface $form_state, VarnishPurgerSettings $settings) {
if (function_exists('purge_tokens_token_info')) {
$tokens = purge_tokens_token_info()['tokens'];
$form['tokens'] = [
'#type' => 'details',
'#group' => 'tabs',
'#title' => $this
->t('Tokens'),
'#description' => $this
->t('<p>Tokens are replaced for the <b>Path</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,
],
],
],
];
foreach ($this->tokenGroups as $token_group) {
foreach (purge_tokens_token_info()['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'],
];
}
}
}
}