You are here

public function ThemeKeyRuleForm::form in ThemeKey 8

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/ThemeKeyRuleForm.php, line 28
Contains Drupal\themekey\Form\ThemeKeyRuleForm.

Class

ThemeKeyRuleForm

Namespace

Drupal\themekey\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $themekey_rule = $this->entity;
  $form['label'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $themekey_rule
      ->label(),
    '#description' => $this
      ->t("Label for the ThemeKeyRule."),
    '#required' => TRUE,
  );
  $form['id'] = array(
    '#type' => 'machine_name',
    '#default_value' => $themekey_rule
      ->id(),
    '#machine_name' => array(
      'exists' => 'themekey_rule_load',
    ),
    '#disabled' => !$themekey_rule
      ->isNew(),
  );
  $properties = $this
    ->getPropertyManager()
    ->getDefinitions();
  $property_options = array();
  foreach ($properties as $property) {
    $property_options[$property['id']] = $property['id'];
  }
  $form['property'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Property'),
    '#options' => $property_options,
    '#default_value' => $themekey_rule
      ->property(),
    '#description' => $this
      ->t("Property for the ThemeKeyRule."),
    '#required' => TRUE,
  );
  $form['key'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Key'),
    '#maxlength' => 255,
    '#default_value' => $themekey_rule
      ->key(),
    '#description' => $this
      ->t("Optional key for the ThemeKeyRule."),
    '#required' => FALSE,
  );
  $operators = $this
    ->getOperatorManager()
    ->getDefinitions();
  $operator_options = array();
  foreach ($operators as $operator) {
    $operator_options[$operator['id']] = $operator['id'];
  }
  $form['operator'] = array(
    '#type' => 'select',
    '#title' => $this
      ->t('Operator'),
    '#options' => $operator_options,
    '#default_value' => $themekey_rule
      ->operator(),
    '#description' => $this
      ->t("Operator for the ThemeKeyRule."),
    '#required' => TRUE,
  );
  $form['value'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Value'),
    '#maxlength' => 255,
    '#default_value' => $themekey_rule
      ->value(),
    '#description' => $this
      ->t("Value for the ThemeKeyRule."),
    '#required' => TRUE,
  );
  $form['theme'] = array(
    '#type' => 'textfield',
    '#title' => $this
      ->t('Theme'),
    '#maxlength' => 255,
    '#default_value' => $themekey_rule
      ->theme(),
    '#description' => $this
      ->t("Theme for the ThemeKeyRule."),
    '#required' => TRUE,
  );
  $form['comment'] = array(
    '#type' => 'textarea',
    '#title' => $this
      ->t('Comment'),
    '#default_value' => $themekey_rule
      ->comment(),
    '#description' => $this
      ->t("Optional comment for the ThemeKeyRule."),
    '#required' => FALSE,
  );
  return $form;
}