function hook_entity_form_mode_alter

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Entity/entity.api.php \hook_entity_form_mode_alter()
  2. 10 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 1873

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

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.