You are here

public function SimpleBlockEditForm::form in Simple Block 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/SimpleBlockEditForm.php, line 18

Class

SimpleBlockEditForm
Base form for simple block edit forms.

Namespace

Drupal\simple_block

Code

public function form(array $form, FormStateInterface $form_state) {
  $simple_block = $this
    ->getEntity();
  $form['title'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Title'),
    '#maxlength' => ConfigEntityStorage::MAX_ID_LENGTH,
    '#default_value' => $simple_block
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $simple_block
      ->id(),
    '#maxlength' => ConfigEntityStorage::MAX_ID_LENGTH,
    '#machine_name' => [
      'source' => [
        'title',
      ],
      'exists' => SimpleBlock::class . '::load',
      'label' => t('Internal name'),
    ],
    '#disabled' => !$simple_block
      ->isNew(),
    '#title' => $this
      ->t('Internal name'),
    '#description' => $this
      ->t('A unique internal name. Can only contain lowercase letters, numbers, and underscores.'),
    '#required' => TRUE,
  ];
  $form['content'] = [
    '#type' => 'text_format',
    '#format' => $simple_block
      ->getContent()['format'],
    '#title' => $this
      ->t('Content'),
    '#default_value' => $simple_block
      ->getContent()['value'],
    '#required' => TRUE,
    '#description' => $this
      ->t('Global tokens are allowed.'),
  ];
  return parent::form($form, $form_state);
}