You are here

protected function EntityTestForm::prepareEntity 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::prepareEntity()
  2. 10 core/modules/system/tests/modules/entity_test/src/EntityTestForm.php \Drupal\entity_test\EntityTestForm::prepareEntity()

Prepares the entity object before the form is built first.

Overrides ContentEntityForm::prepareEntity

File

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

Class

EntityTestForm
Form controller for the test entity edit forms.

Namespace

Drupal\entity_test

Code

protected function prepareEntity() {
  if (empty($this->entity->name->value)) {

    // Assign a random name to new EntityTest entities, to avoid repetition in
    // tests.
    $random = new Random();
    $this->entity->name->value = $random
      ->name();
  }
}