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 you do a search (view) and some entities in the index are not available any more, you get a bunch of notices (see below). As that probably can happen sometimes, this case should probably be handled better.
# Notice: Trying to get property of non-object in entity_extract_ids() (line 7065 of /...../includes/common.inc).
# Notice: Trying to get property of non-object in node_uri() (line 250 of /...../modules/node/node.module).
# Notice: Undefined index: title in SearchApiViewsHandlerField->render() (line 131 of /...../profiles/recruiter/modules/search_api/contrib/search_api_views/includes/handler_field.inc).
# Notice: Undefined index: search_api_views_entity in SearchApiViewsHandlerField->renderLink() (line 176 of /...../profiles/recruiter/modules/search_api/contrib/search_api_views/includes/handler_field.inc).
# Notice: Trying to get property of non-object in entity_extract_ids() (line 7065 of /...../includes/common.inc).
# Notice: Trying to get property of non-object in node_uri() (line 250 of /...../modules/node/node.module).
Comment | File | Size | Author |
---|---|---|---|
#3 | views_missing_entities.patch | 642 bytes | drunken monkey |
#1 | views_missing_entities.patch | 1004 bytes | drunken monkey |
Comments
Comment #1
drunken monkeyHm, normally,
hook_entity_delete()
should take care that the entity isn't returned anymore, so I don't really know when a result wouldn't be available.However, I tried it with a little more checks. Does this help?
Comment #2
fagoyep, however I guess it would be better to don't add the row to views at all + reduce the result count?
Indeed hook_entity_delete() should take care of those - I experienced it by using it wrong: query the solr server of another site... But I guess I can happen in practice too, consider someone searching after an entity is deleted, but the hook is not yet called.
Comment #3
drunken monkeyOK, the time between deletion and hook invocation should be around one millisecond, so I don't think this is very likely. But sure, we should get this, and you're absolutely right that just not displaying the row is way better. I just thought, this would be harder to do, but in the end I just had to delete one line. Patchj attached. ;)
Comment #4
drunken monkeyCommitted.
Comment #5
fagoThat works fine for me, however the pager is not yet updated. I guess we would have to fix $this->pager->total_items too.
Comment #6
drunken monkeyHow would you propose to fix this? Or, what would you say is wrong with the pager currently?
As I see it, there is no way to tell how many "loadable" results there really are, and just subtracting the unloadable items of the current page from the total count would possibly make the last page invisible, along with the results there. I think the field is correct as it is.
Also, we're dealing with a complete edge case here. I think, just avoiding to show warnings or the like is all we need to do.
Comment #7
fago>Also, we're dealing with a complete edge case here.
Agreed, so let's just leave it like that. I was not sure about it either.