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.
Problem/Motivation
Currently SearchApiViewsQuery::get_result_wrappers()
uses the array key of the passed in $results
as entity id. At least in some scenarios $results
comes directly from the view results.
Unfortunately there's no guarantee that $results
is keyed by the entity_id.
Please check following issue for further information: #1350814: EntityFieldHandlerHelper should not use views row_index as entity_id
Proposed resolution
Please see the attached patch for a possible solution.
Remaining tasks
Review attached patch.
Check if there are other locations where the row-index is used as entity_id.
User interface changes
none.
API changes
none.
Comment | File | Size | Author |
---|---|---|---|
search_api-dont-use-views-row-index-as-entity-id.patch | 2.21 KB | das-peter | |
Comments
Comment #1
drunken monkeyWe set the Views result ourselves, so I'm pretty sure we can guarantee that the row indexes are the entity IDs. Otherwise, please provide a counter-example and re-open.
The issue for the Entity API seems valid, though – I don't think this relation between row indexes and entity IDs is specified anywhere.
Comment #2
das-peter CreditAttribution: das-peter commentedNo we can't - especially if you use some advanced use cases.
That's why I explicitly linked to views_content_plugin_style_ctools_context (see line 31-34) in #1350814: EntityFieldHandlerHelper should not use views row_index as entity_id.
This is what you can see there:
This means if I use this ctools plugin to output my content, it will actively reset the row_index.
And even if this behaviour could be interpreted as somehow special, it doesn't violate any definition - because there's no definition that row_index has to be a special value at all.
The provided patch would make the views integration immune from such changes.
Is there any reason why not to make the code more solid? Especially if there are no drawbacks of any kind, which seems to be the case here.
Comment #3
drunken monkeyTo be fair, with „there's no definition“ you can do pretty much anything in Views – but I do see your point, and even if I don't think it's a very sensible thing to do by the Ctools plugin, I guess there really is no harm in making our side more robust.
Committed your patch, thanks!
Comment #4
das-peter CreditAttribution: das-peter commentedThank you very much for committing this :)