Problem/Motivation
function foo_entity_delete(EntityInterface $entity) {
$context = EntityContext::fromEntity($entity);
}
This will fail.
Introduced in #2791269: Allow saving pre-existing references to inaccessible items
Proposed resolution
If \Drupal\Core\Entity\Plugin\Validation\Constraint\ValidReferenceConstraintValidator::validate()
can't load the unchanged entity from the DB (because it no longer exists), use the one we have
This ticket is now a clean up of a todo and update InlineBlockEntityOperations::handleEntityDelete() to use isLayoutCompatibleEntity()
Remaining tasks
N/A
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|
Issue fork drupal-3008943
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
tim.plunkettComment #4
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI wonder what's the use case for validating an entity after it has been deleted from the storage. The issue title says that the entity is being deleted, but that's not really accurate, the entity is already gone.
Comment #5
tim.plunkettIt's not actually the validating I'm hitting, it's
EntityContext::fromEntity($entity)
, which is easily triggered that way.When a custom block is deleted, Layout Builder has to find all of the usages of that block in order to remove the reference to it. See #2957425: Allow the inline creation of non-reusable Custom Blocks in the layout builder, and
layout_builder_entity_delete()
/\Drupal\layout_builder\InlineBlockEntityOperations::handleEntityDelete()
.Because TypedData, everything all the way down the chain, even the now-deleted block, is instantiated.
Comment #6
phenaproximaI think the test could benefit from a comment explaining why we're calling validate(), but otherwise this looks good and is ready to go.
Comment #7
tim.plunkettNah, let's just be explicit about what we're testing. No need to mess with ::validate()
Comment #8
tim.plunkettHere's a pass/fail version, to prove we're actually still testing it without the validate() part
Comment #9
phenaproximaI like it. RTBC on the assumption that it will look like Christmas in an hour.
Comment #11
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI'd like to take another look at the patch as well, hopefully there's no rush to commit it..
Comment #12
tim.plunkettLet's do this, as I definitely want your input.
Comment #13
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI've been staring for a while at
\Drupal\layout_builder\InlineBlockEntityOperations::handleEntityDelete()
and all its possible code paths, and I can't find what would trigger a call toEntityContext::fromEntity($entity)
in there..Is there some other part of the code that I should also be looking at? :)
Comment #14
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOops, didn't want to un-assign, I'm still looking into it.
Comment #16
alexpottThis looks very reasonable - but perhaps a code comment might be a good idea - so people know when we might use the passed in entity instead of the unchanged one.
Comment #18
jhedstromSetting to NW for the code comment mentioned in #16.
Comment #23
larowlanTagging to get some eyes to add the comment
Comment #24
yogeshmpawarUpdated patch with reroll diff & addressed #16
Comment #25
yogeshmpawarComment #28
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #29
Rishabh Vishwakarma CreditAttribution: Rishabh Vishwakarma at OpenSense Labs for DrupalFit commentedAdding patch against 10.0.1
Comment #30
ameymudras CreditAttribution: ameymudras at Salsa Digital commentedDid a brief code review and the following comment doesn't make sense to me, I think we should reword it. Otherwise, the code looks good
// We might use the passed entity instead of the unchanged one.
Comment #31
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Material for Drupal India Association commentedMade change to the comment as per #30 so the comment is now quite relevant what it supposed to do.
Comment #32
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Material for Drupal India Association commentedComment #33
smustgrave CreditAttribution: smustgrave at Mobomo commentedAttempted to replicate this by running the code in the issue summary and I don't get any error in 10.1
Can someone please confirm if it's still an issue and update the issue summary with additional steps
Thanks!
Comment #34
tim.plunkettI think the codepath described by the test case (introduced in #7) was at one time relevant to how Layout Builder was working, but is not reproducible anymore in core. And I can't think of a reason why you'd need to do it in custom code either.
Comment #35
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedThere's still a reference in code to this issue in
\Drupal\layout_builder\InlineBlockEntityOperations::handleEntityDelete()
, let's see if callingisLayoutCompatibleEntity()
is possible now.Comment #37
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedOpened a MR, let's see how it goes.
Comment #38
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue.
While you are making the above changes, we recommend that you convert this patch to a merge request. Merge requests are preferred over patches. Be sure to hide the old patch files as well. (Converting an issue to a merge request without other contributions to the issue will not receive credit.)
Comment #39
amateescu CreditAttribution: amateescu for Tag1 Consulting commentedHiding the patches because the MR seems to work well :)
Comment #40
smustgrave CreditAttribution: smustgrave at Mobomo commentedUpdated title and solution to mention this seems to be cleaning up a todo and use isLayoutCompatibleEntity().
Comment #41
alexpottAdded a question the MR.
Comment #42
smustgrave CreditAttribution: smustgrave at Mobomo commentedMoving to NW for someone to test that proposal.