You are here

function hook_entity_form_mode_alter in Drupal 10

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_form_mode_alter()

Change the form mode used to build an entity form.

Parameters

string $form_mode: The form_mode that is to be used to build the entity form.

\Drupal\Core\Entity\EntityInterface $entity: The entity for which the form is being built.

Related topics

1 function implements hook_entity_form_mode_alter()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

entity_test_entity_form_mode_alter in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_form_mode_alter().

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1839
Hooks and documentation related to entities.

Code

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';
  }
}