Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Matroskeen on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
9.2.x
Introduced in version:
9.2.0
Issue links:
Description:
hook_entity_form_mode_alter() hook was added to allow modules to override form mode based on some conditions. For example, different form modes can be applied based on user role.
Example:
function hook_entity_form_mode_alter(&$form_mode, Drupal\Core\Entity\EntityInterface $entity) {
// Change the form mode for users with Administrator role.
if ($entity->getEntityTypeId() == 'user' && $entity->hasRole('administrator')) {
$form_mode = 'my_custom_form_mode';
}
}
Impacts:
Module developers