hook_entity_form_display_alter

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

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

Entity CRUD, editing, and view hooks
Hooks used in various entity operations.
Hooks
Define functions that alter the behavior of Drupal core.

File

core/lib/Drupal/Core/Entity/entity.api.php, line 1637
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', array(
      'type' => 'hidden',
    ));
  }
}
doc_Drupal
2016-10-29 09:17:59
Comments
Leave a Comment

Please login to continue.