Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If an entity is being loaded or output within an entityreference field, there should be a way of accessing the host entity.
AFAICT, this doesn't exist.
This affects contrib -- eg in #2585447: Entity Access does not check host entity, Paragraphs module is having to add fields to the paragraph entity to store the host entity type and ID.
Comments
Comment #3
BerdirI don't see how entity reference could do this. You can always do a query, that's already possible. It's just not very fast.
The concept of a host entity only makes sense for entity types that only have a single entity that references them, like paragraphs. The only thing that could be in core is the code from ERR to automatically set those fields.
Comment #4
joachim CreditAttribution: joachim commented> The concept of a host entity only makes sense for entity types that only have a single entity that references them, like paragraphs.
I don't mean something permanent, but something contextual.
Here's an example: suppose on the current page you can see nodes Host 1 and Host 2, and they both have a reference field which contains Child 1.
The field formatter for the reference field on Host 1 has the Child 1 entity passed to it. This copy of the entity should be able to tell you that it's being hosted by Host 1.
The reference field formatter on Host 2 should be able to tell you it's being hosted by Host 2.
Comment #5
BerdirThat is problematic for render caching. Child 1 will be rendered only once when it is displayed in the same view mode. This would mean that render caching would require to vary by the host entity.
Comment #17
smustgrave CreditAttribution: smustgrave at Mobomo commentedClosing as outdated since this moved to PNMI 6 years ago without an updated IS
If still an issue please reopen with an updated issue summary. Thanks