Returns the entity_form_display object used to render an entity form.
This function should only be used internally when rendering an entity form. When assigning suggested form display options for a component in a given form mode, entity_get_form_display() should be used instead, in order to avoid inadvertently modifying the output of other form modes that might happen to use the 'default' form display too. Those options will then be effectively applied only if the form mode is configured to use them.
\Drupal\Core\Entity\EntityInterface $entity: The entity for which the form is being rendered.
string $form_mode: The form mode being rendered.
\Drupal\entity\Plugin\Core\Entity\EntityFormDisplay The form display object that should be used to render the entity form.
function entity_get_render_form_display(EntityInterface $entity, $form_mode) {
$entity_type = $entity
->entityType();
$bundle = $entity
->bundle();
// @todo Form modes don't have custom settings yet, so just return the display
// for the form mode that was requested.
$form_display = entity_get_form_display($entity_type, $bundle, $form_mode);
$form_display->originalMode = $form_mode;
return $form_display;
}