protected function ImageFieldTokensTestingTrait::entityGetFormDisplay in ImageField Tokens 8
Same name and namespace in other branches
- 8.2 tests/src/Functional/ImageFieldTokensTestingTrait.php \Drupal\Tests\imagefield_tokens\Functional\ImageFieldTokensTestingTrait::entityGetFormDisplay()
Returns the entity form display associated with a bundle and form mode.
The function reads the entity form display object from the current configuration, or returns a ready-to-use empty one if no configuration entry exists yet for this bundle and form mode. This streamlines manipulation of entity form displays by always returning a consistent object that reflects the current state of the configuration.
Parameters
string $entity_type: The entity type.
string $bundle: The bundle.
string $form_mode: The form mode.
Return value
\Drupal\Core\Entity\Display\EntityFormDisplayInterface The entity form display associated with the given form mode.
See also
\Drupal\Core\Entity\EntityStorageInterface::create()
\Drupal\Core\Entity\EntityStorageInterface::load()
File
- tests/
src/ Functional/ ImageFieldTokensTestingTrait.php, line 145
Class
- ImageFieldTokensTestingTrait
- Provides a helper method for creating Image fields.
Namespace
Drupal\Tests\imagefield_tokens\FunctionalCode
protected function entityGetFormDisplay($entity_type, $bundle, $form_mode) : EntityFormDisplayInterface {
// Try loading the entity from configuration.
$entity_form_display = EntityFormDisplay::load($entity_type . '.' . $bundle . '.' . $form_mode);
// If not found, create a fresh entity object. We do not primitively create
// new entity form display configuration entries for each existing entity
// type and bundle whenever a new form mode becomes available. Instead,
// configuration entries are only created when an entity form display is
// explicitly configured and saved.
if (!$entity_form_display) {
$entity_form_display = EntityFormDisplay::create([
'targetEntityType' => $entity_type,
'bundle' => $bundle,
'mode' => $form_mode,
'status' => TRUE,
]);
}
return $entity_form_display;
}