You are here

public function SettingsForm::buildForm in Build Hooks 8

Same name and namespace in other branches
  1. 8.2 src/Form/SettingsForm.php \Drupal\build_hooks\Form\SettingsForm::buildForm()
  2. 3.x src/Form/SettingsForm.php \Drupal\build_hooks\Form\SettingsForm::buildForm()

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/SettingsForm.php, line 59

Class

SettingsForm
Class SettingsForm.

Namespace

Drupal\build_hooks\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('build_hooks.settings');
  $form['build_hook'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Build hook'),
    '#description' => $this
      ->t('Enter build hook'),
    '#maxlength' => 64,
    '#size' => 64,
    '#default_value' => $config
      ->get('build_hook'),
  ];
  $form['divider_line'] = [
    '#markup' => '<h2>' . $this
      ->t('Triggers') . '</h2>' . '<hr/>',
  ];
  $form['divider_user'] = [
    '#markup' => '<h4>' . $this
      ->t('User Interaction') . '</h4>',
  ];
  $form['menu'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Execute via toolbar'),
    '#default_value' => $config
      ->get('triggers.menu'),
  ];
  $form['divider_automatic'] = [
    '#markup' => '<h4>' . $this
      ->t('Automatic') . '</h4>',
  ];
  $form['cron'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Execute via cron'),
    '#default_value' => $config
      ->get('triggers.cron'),
  ];
  $form['divider_node'] = [
    '#markup' => '<h4>' . $this
      ->t('Node Update') . '</h4>',
  ];
  foreach ($this
    ->getNodeTypes() as $nodeType) {
    $form['node_type_' . $nodeType
      ->id()] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t($nodeType
        ->label()),
      '#default_value' => $config
        ->get('triggers.node.' . $nodeType
        ->id()),
    ];
  }
  $form['divider_messages'] = [
    '#markup' => '<h2>' . $this
      ->t('Messages') . '</h2>' . '<hr/>',
  ];
  $form['show'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Show Message'),
    '#default_value' => $config
      ->get('messages.show'),
  ];
  $form['log'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Log Message'),
    '#default_value' => $config
      ->get('messages.log'),
  ];
  return parent::buildForm($form, $form_state);
}