Returns the entity_form_display object associated to 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 configuration entry exists yet for this bundle and form mode. This streamlines manipulation of EntityFormDisplay objects by always returning a consistent object that reflects the current state of the configuration.
Example usage:
entity_get_form_display('node', 'article', 'default')
->setComponent('body', array(
'type' => 'text_textarea_with_summary',
'weight' => 1,
))
->setComponent('field_image', array(
'type' => 'hidden',
))
->save();
string $entity_type: The entity type.
string $bundle: The bundle.
string $form_mode: The form mode.
\Drupal\entity\Plugin\Core\Entity\EntityFormDisplay The EntityFormDisplay object associated to the form mode.
function entity_get_form_display($entity_type, $bundle, $form_mode) {
// Try loading the entity from configuration.
$entity_form_display = entity_load('entity_form_display', $entity_type . '.' . $bundle . '.' . $form_mode);
// If not found, create a fresh entity object. We do not preemptively create
// new EntityFormDisplay configuration entries for each existing entity type
// and bundle whenever a new form mode becomes available. Instead,
// configuration entries are only created when a EntityFormDisplay object is
// explicitly configured and saved.
if (!$entity_form_display) {
$entity_form_display = entity_create('entity_form_display', array(
'targetEntityType' => $entity_type,
'bundle' => $bundle,
'mode' => $form_mode,
));
}
return $entity_form_display;
}