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

Alter the settings used for displaying an entity form.

Parameters

\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display: The entity_form_display object that will be used to display the entity form components.

array $context: An associative array containing:

  • entity_type: The entity type, e.g., 'node' or 'user'.
  • bundle: The bundle, e.g., 'page' or 'article'.
  • form_mode: The form mode; e.g., 'default', 'profile', 'register', etc.

Related topics

3 functions implement hook_entity_form_display_alter()

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

content_moderation_entity_form_display_alter in core/modules/content_moderation/content_moderation.module
Implements hook_entity_form_display_alter().
entity_test_entity_form_display_alter in core/modules/system/tests/modules/entity_test/entity_test.module
Implements hook_entity_form_display_alter().
layout_builder_entity_form_display_alter in core/modules/layout_builder/tests/modules/layout_builder_test/layout_builder_test.module
Implements hook_entity_form_display_alter().

File

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

Code

function hook_entity_form_display_alter(\Drupal\Core\Entity\Display\EntityFormDisplayInterface $form_display, array $context) {

  // Hide the 'user_picture' field from the register form.
  if ($context['entity_type'] == 'user' && $context['form_mode'] == 'register') {
    $form_display
      ->setComponent('user_picture', [
      'region' => 'hidden',
    ]);
  }
}