You are here

public function ThemeKeyRuleChainForm::buildForm in ThemeKey 8

Form constructor.

Parameters

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

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/ThemeKeyRuleChainForm.php, line 42

Class

ThemeKeyRuleChainForm
Provides a form for administering the ThemeKey rule chain.

Namespace

Drupal\themekey\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $ruleChainManager = $this
    ->getRuleChainManager();
  if (!$form_state
    ->isSubmitted()) {
    $ruleChainManager
      ->rebuildChain();
  }
  $form['#title'] = $this
    ->t('ThemeKey Rule Chain');
  $form['table'] = array(
    '#theme' => 'themekey_rule_chain_table',
    '#tree' => TRUE,
  );
  $depth = 0;
  $ruleChain = $ruleChainManager
    ->getChain();
  foreach ($ruleChain as $ruleId => $ruleMetaData) {
    $form['table'][$ruleId] = array(
      '#type' => 'fieldset',
      '#title' => $ruleId,
    );
    $form['table'][$ruleId]['enabled'] = array(
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enabled'),
      '#default_value' => $ruleMetaData['enabled'],
    );
    $form['table'][$ruleId]['weight'] = array(
      '#type' => 'weight',
      '#title' => $this
        ->t('Weight'),
      '#default_value' => $ruleMetaData['weight'],
      '#delta' => 100,
    );
    $form['table'][$ruleId]['parent'] = array(
      '#type' => 'textfield',
      '#title' => $this
        ->t('Parent'),
      '#default_value' => $ruleMetaData['parent'],
    );
    $form['table'][$ruleId]['depth'] = array(
      '#type' => 'value',
      '#value' => $ruleMetaData['depth'],
    );
  }
  $form['save'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Save rule chain'),
  );
  return $form;
}