diff --git a/entity_usage.module b/entity_usage.module index fc579e88558b2e8c6a88762efcc1f36a84d97408..06f655201f39bb4ffd2b42b40f55660c05b9ac8f 100644 --- a/entity_usage.module +++ b/entity_usage.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Cache\CacheableMetadata; +use Drupal\Core\Entity\EntityFormInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -85,7 +86,7 @@ function entity_usage_field_storage_config_delete(FieldStorageConfigInterface $f */ function entity_usage_form_alter(&$form, FormStateInterface $form_state, $form_id) { $form_object = $form_state->getFormObject(); - if (!method_exists($form_object, 'getEntity')) { + if (!$form_object instanceof EntityFormInterface) { return; } /** @var \Drupal\Core\Entity\EntityInterface $entity */ @@ -107,7 +108,7 @@ function entity_usage_form_alter(&$form, FormStateInterface $form_state, $form_i if (!in_array($entity_type_id, $edit_entity_types) && !in_array($entity_type_id, $delete_entity_types)) { return; } - $is_edit_form = method_exists($form_object, 'getOperation') && $form_object->getOperation() === 'edit' && in_array($entity_type_id, $edit_entity_types); + $is_edit_form = $form_object->getOperation() === 'edit' && in_array($entity_type_id, $edit_entity_types); $is_delete_form = FALSE; if (!$is_edit_form && in_array($entity_type_id, $delete_entity_types)) { // Even if this is not on the UI, sites can define additional form classes