You are here

public function SpamicideForm::form in Spamicide 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/SpamicideForm.php, line 51

Class

SpamicideForm
Spamicide form.

Namespace

Drupal\spamicide\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $spamicide = $this->entity;

  // Support to set a default form_id through a query argument.
  $request = $this->requestStack
    ->getCurrentRequest();
  if ($spamicide
    ->isNew() && !$spamicide
    ->id() && $request->query
    ->has('form_id')) {
    $spamicide
      ->set('formId', $request->query
      ->get('form_id'));
    $spamicide
      ->set('label', $request->query
      ->get('form_id'));
  }
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Form ID name'),
    '#maxlength' => 255,
    '#default_value' => $spamicide
      ->label(),
    '#description' => $this
      ->t('Label for the spamicide.'),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $spamicide
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\spamicide\\Entity\\Spamicide::load',
    ],
    '#disabled' => !$spamicide
      ->isNew(),
  ];
  $form['status'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enabled'),
    '#default_value' => $spamicide
      ->status(),
  ];
  return $form;
}