You are here

public function CacheflushEntityForm::presetForm in CacheFlush 8

1 call to CacheflushEntityForm::presetForm()
CacheflushEntityForm::buildForm in modules/cacheflush_ui/src/Entity/Form/CacheflushEntityForm.php
Form constructor.

File

modules/cacheflush_ui/src/Entity/Form/CacheflushEntityForm.php, line 125

Class

CacheflushEntityForm
Form controller for Cacheflush entity edit forms.

Namespace

Drupal\cacheflush_ui\Entity\Form

Code

public function presetForm(&$form, &$form_state) {
  $storage = $form_state
    ->getStorage();

  // Form element, vertical tab parent.
  $form['cacheflush_vertical_tabs'] = [
    '#type' => 'vertical_tabs',
    '#weight' => 50,
  ];

  // Add vertical tabs.
  $storage['cacheflush_tabs'] = $this->moduleHandler
    ->invokeAll('cacheflush_ui_tabs');
  $original_tabs = cacheflush_ui_cacheflush_ui_tabs();
  foreach ($storage['cacheflush_tabs'] as $key => $value) {
    $form[$key] = [
      '#type' => 'details',
      '#title' => Html::escape($value['name']),
      '#group' => 'cacheflush_vertical_tabs',
      '#weight' => isset($value['weight']) ? $value['weight'] : NULL,
      '#attributes' => isset($original_tabs[$key]) ? [
        'class' => [
          'original_tabs',
        ],
      ] : [],
      '#tree' => TRUE,
    ];
  }

  // Adding table elemnts to tabs.
  $storage['preset_options'] = $this->cacheflush
    ->getOptionList();
  $data = $this->entity
    ->getData();
  foreach ($storage['preset_options'] as $key => $value) {

    // Special tab element added only if there module are instaled.
    if ($value['category'] == 'vertical_tabs_often' && !$this->moduleHandler
      ->moduleExists($key)) {
      continue;
    }
    $form[$value['category']][$key] = [
      '#type' => 'checkbox',
      '#title' => Html::escape($key),
      '#default_value' => isset($data[$key]) ? 1 : 0,
      '#description' => Html::escape($value['description']),
    ];
  }
  $this
    ->tabsDescription($form);
  $storage['presets'] = [];
  $storage['data'] = $data;
  $form_state
    ->setStorage($storage);
}