You are here

public function EntityTestForm::form in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/entity_test/src/EntityTestForm.php \Drupal\entity_test\EntityTestForm::form()
  2. 10 core/modules/system/tests/modules/entity_test/src/EntityTestForm.php \Drupal\entity_test\EntityTestForm::form()

Gets the actual form array to be built.

Overrides ContentEntityForm::form

See also

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

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

File

core/modules/system/tests/modules/entity_test/src/EntityTestForm.php, line 31

Class

EntityTestForm
Form controller for the test entity edit forms.

Namespace

Drupal\entity_test

Code

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

  // @todo: Is there a better way to check if an entity type is revisionable?
  if ($entity
    ->getEntityType()
    ->hasKey('revision') && !$entity
    ->isNew()) {
    $form['revision'] = [
      '#type' => 'checkbox',
      '#title' => t('Create new revision'),
      '#default_value' => $entity
        ->isNewRevision(),
    ];
  }
  return $form;
}