public function VarnishPurgerFormBase::buildFormHeaders in Varnish purger 8
Same name and namespace in other branches
- 8.2 src/Form/VarnishPurgerFormBase.php \Drupal\varnish_purger\Form\VarnishPurgerFormBase::buildFormHeaders()
Build the 'headers' section of the form.
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::buildFormHeaders()
- VarnishPurgerFormBase::buildForm in src/
Form/ VarnishPurgerFormBase.php - Form constructor.
File
- src/
Form/ VarnishPurgerFormBase.php, line 201
Class
- VarnishPurgerFormBase
- Abstract form base for Varnish based configurable purgers.
Namespace
Drupal\varnish_purger\FormCode
public function buildFormHeaders(array &$form, FormStateInterface $form_state, VarnishPurgerSettings $settings) {
if (is_null($form_state
->get('headers_items_count'))) {
$value = empty($settings->headers) ? 1 : count($settings->headers);
$form_state
->set('headers_items_count', $value);
}
$form['headers'] = [
'#type' => 'details',
'#group' => 'tabs',
'#title' => $this
->t('Headers'),
'#description' => $this
->t('Configure the outbound HTTP headers, leave
empty to delete. Example for Tag as Type: Cache-Tags for Header and
[invalidation:expression] for Value.'),
];
$form['headers']['headers'] = [
'#tree' => TRUE,
'#type' => 'table',
'#header' => [
$this
->t('Header'),
$this
->t('Value'),
],
'#prefix' => '<div id="headers-wrapper">',
'#suffix' => '</div>',
];
for ($i = 0; $i < $form_state
->get('headers_items_count'); $i++) {
if (!isset($form['headers']['headers'][$i])) {
$header = isset($settings->headers[$i]) ? $settings->headers[$i] : [
'field' => '',
'value' => '',
];
$form['headers']['headers'][$i]['field'] = [
'#type' => 'textfield',
'#default_value' => $header['field'],
'#attributes' => [
'style' => 'width: 100%;',
],
];
$form['headers']['headers'][$i]['value'] = [
'#type' => 'textfield',
'#default_value' => $header['value'],
'#attributes' => [
'style' => 'width: 100%;',
],
];
}
}
$form['headers']['add'] = [
'#type' => 'submit',
'#name' => 'add',
'#value' => t('Add header'),
'#submit' => [
[
$this,
'buildFormHeadersAdd',
],
],
'#ajax' => [
'callback' => [
$this,
'buildFormHeadersRebuild',
],
'wrapper' => 'headers-wrapper',
'effect' => 'fade',
],
];
}