function hook_entity_prepare_form hook_entity_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) Acts on an entity object about to be shown on an entity form. This can be typically used to pre-fill entity values or change the form state before the entity form is built. It is invoked just once when first building the entity form. Rebuilds will not trigger a new invocation. Parameters  \Drupal\Core\Entity\EntityInterface $entity: The entity that is about to be shown on the form. $operation: The current operation. \Drupal\Core\Form\FormStateInterface $form_state: The current state of the form. See also  \Drupal\Core\Entity\EntityForm8b7c:f320:99b9:690f:4595:cd17:293a:c069prepareEntity() hook_ENTITY_TYPE_prepare_form() 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 1596 Hooks and documentation related to entities.  Code function hook_entity_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) {
  if ($operation == 'edit') {
    $entity->label->value = 'Altered label';
    $form_state->set('label_altered', TRUE);
  }
}


    
{'path': 'public/docs/drupal~8/core-lib-drupal-core-entity-entity.api.php/function/hook_entity_prepare_form/8.1.x.html', 'source': 'DevDocs.IO'}