You are here

public function MessageDigestIntervalForm::form in Message Digest 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/MessageDigestIntervalForm.php, line 16

Class

MessageDigestIntervalForm
Config form for message digest intervals.

Namespace

Drupal\message_digest\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var \Drupal\message_digest\Entity\MessageDigestIntervalInterface $interval */
  $interval = $this->entity;
  $form['label'] = [
    '#title' => $this
      ->t('Label'),
    '#type' => 'textfield',
    '#default_value' => $interval
      ->label(),
    '#description' => $this
      ->t('Label for this interval.'),
    '#required' => TRUE,
    '#size' => 30,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#title' => $this
      ->t('Machine name'),
    '#default_value' => $interval
      ->id(),
    '#disabled' => !$interval
      ->isNew(),
    '#machine_name' => [
      'exists' => [
        '\\Drupal\\message_digest\\Entity\\MessageDigestInterval',
        'load',
      ],
      'source' => [
        'label',
      ],
    ],
  ];
  $form['interval'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Interval'),
    '#required' => TRUE,
    '#default_value' => $interval
      ->getInterval(),
    '#description' => $this
      ->t('A <a href=":url">relative format</a>, such as <em>1 week</em> or <em>1 day</em>.', [
      ':url' => 'http://php.net/manual/en/datetime.formats.relative.php',
    ]),
  ];
  $form['description'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Description'),
    '#default_value' => $interval
      ->getDescription(),
  ];
  return $form;
}