You are here

protected function EntityTestForm::prepareEntity in Drupal 9

Same name and namespace in other branches
  1. 8 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();
  }
}