I propose to add the entity type label and entity id to \Drupal\entity_reference_integrity_enforce\EntityPredelete::entityDelete exception text.

I have seen this message in my watchdog/dblog and have no way of finding out why it happened. In my case, I can only tell it happened in a batch process.

Short version of my proposal:

Before: throw new ProtectedEntityException('Cannot delete entity that has references pointing to it.');
After: throw new ProtectedEntityException(sprintf('Cannot delete entity %s with id %d that has references pointing to it.', ...));

Comments

Gogowitsch created an issue. See original summary.

rogerpfaff’s picture

Status: Active » Needs review
StatusFileSize
new886 bytes

Here is a patch that replaces the message like said in opening. I can't test because I have no clue how to reproduce the error.

jepster_’s picture

Status: Needs review » Reviewed & tested by the community

Successful code review.

gogowitsch’s picture

Assigned: gogowitsch » Unassigned
Issue summary: View changes

+1 from me: this patch has been in production for a while now, and works as intended.

From my perspective: ok to get commited.

sam152’s picture

+++ b/modules/entity_reference_integrity_enforce/src/EntityPredelete.php
@@ -50,7 +50,7 @@ class EntityPredelete implements ContainerInjectionInterface {
-      throw new ProtectedEntityException('Cannot delete entity that has references pointing to it.');
+      throw new ProtectedEntityException(sprintf('Cannot delete entity %s with id %d that has references pointing to it.', [$entity->label(), $entity->id()]));

I have never seen the pattern of sprintf('..', [arg, arg]), lets go ('..', arg, arg). Also, maybe worth some quotes around the arguments, so it's clear which part is coming from the entity. We are also missing bits of context such as the entity type and bundle, which seem like they would also be useful.

What about:

Cannot delete "{{ entity type id }}" of type "{{ bundle id }}" with label "{{ label }}" and ID "{{ id }}" because other content is referencing it and the integrity of this entity type is enforced.

sam152’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new4.06 KB
sam152’s picture

  • Sam152 committed ffcc7a6 on 8.x-1.x authored by rogerpfaff
    Issue #3016389 by Sam152, rogerpfaff, Gogowitsch, Peter Majmesku:...
sam152’s picture

sam152’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.