When in a function (e.g. a hook_form_alter) is there a reliable way to determine if the form is an entity form and if so, what type of entity?
1 Answer
You can check if the form is an instance of EntityForm and then get the entity to check the entity type:
if ($form_state->getFormObject() instanceof \Drupal\Core\Entity\EntityFormInterface) {
$entity_type = $form_state->getFormObject()->getEntity()->getEntityTypeId();
}