Closed (fixed)
Project:
Search API
Version:
8.x-1.x-dev
Component:
Views integration
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Oct 2016 at 12:56 UTC
Updated:
17 Jan 2019 at 12:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
merilainen commentedThis seems quite major feature. Is there any other way to get rendered entity + excerpt at the moment? I don't want to add fields to the view because different content types have different fields and they are a lot easier to manage in the display mode settings.
Comment #3
drunken monkeyAre you sure this was possible in D7?
But it's a good idea anyways, sure. Just not a priority at the moment.
Comment #4
recrit commentedThe attached patch adds a Rendered Entity views field for Search API.
Comment #5
recrit commentedUpdated search_api.views.schema.yml with the new field.
Comment #6
drunken monkeyI haven't tested the patch yet, but it already looks pretty good, thanks a lot!
However, I do have several high-level remarks:
_search_api_views_data_special_fields().SearchApiRow. In my opinion, it should just work exactly the same way.Comment #7
recrit commentedYes, this was loosely based on
1. I was try to get it added to hook_views_data and _search_api_views_data_special_fields() does not get passed the $datasource which was needed to determine $entity_type->hasViewBuilderClass().
2. You can configure a mixed entity type index. In the index configuration, check on Content and Taxonomy Term. Use case = Taxonomy vocabularies that are used as landing pages for all the content tagged with their terms. That said, it's probably best practice to have common view modes for each entity type.
3. This was loosely based on Drupal\views\Plugin\views\field\RenderedEntity and SearchApiRow. The former was used to get the translation rendering correct. If the datasource viewItem() does this, then entity types could be abstracted out of it.
Comment #8
miiimoooHere is a new patch loosely based on @recrit's patch.
I've tried to take on board your suggestions.
There is now one Rendered Entity field per datasource.
In the options form the UI could be improved. I notice that in some views' fields view modes can be chosen per bundle, in others per entity type. So I tried to support both.
Comment #10
miiimoooMissed some dependency..
Comment #12
miiimoooPhew..
Comment #13
drunken monkeyA lot better already, thanks!
Still some complaints, though:
\Drupal\search_api\Plugin\views\row\SearchApiRow.'real field'entry which the other "special fields" have – see attached patch.field_item:rendered_entitydata type? Why do you add that? The field handler isn't even designed to work with an individual field, so even if the declaration had any effect, it would just be to produce a bug.getEntity()can just use$values->_item->getOriginalObject(), which will always work.ViewsTest, though.Comment #14
miiimoooBack again, thanks for all your suggestions:
re 1&2 - I've renamed everything to Item/_item and used more or less a copy of SearchApiRow as you suggested.
re 4 - no idea, but removed now
re 6 I'm trying to work on this now
Comment #15
miiimoooFix schema
Comment #16
drunken monkeyThanks, good job! Found some minor problems (some of them also present in the row plugin), but otherwise this only seems to need tests. (Unless my edits broke something.)
In the future, please just also include an interdiff when posting new patch revisions. (Though, I guess, in the case of #14 the interdiff is pretty useless.)
Comment #18
drunken monkeyOops, sorry, stupid mistake – confused the Views' special
defineOptions()with the Plugin API'sdefaultConfiguration().Comment #19
abrammI'm getting the following PHP warning with patch #18 (Search API 8.x-1.7):
It still works fine though.
Comment #20
abrammHere we go. The entityTypeManager property as well as corresponding getter and setter are already declared in SearchApiFieldTrait.
Comment #21
drunken monkeyThanks for spotting and already fixing this, looks good!
Now it seems this just needs tests and we can commit it. (Additionally, other people confirming it works for them would of course also be great.)
Comment #22
hannessmany many thanks for this patch!
it saved me in leaflet based view where i can select a node display or fields for the popup in normal views, but only fields in search api based views.
so RTBC from my side (as soon as tests are implemented)
Comment #23
iamdroid commentedPatch #20 works great for me.
Thanks a lot, guys!
Comment #24
drunken monkeyAlright, thanks for reporting back!
Since there seems to be a lot of interest (and positive feedback), I now went ahead and also added the tests. If the attached patch still works for everyone (and passes the tests), I can finally commit it.
Comment #25
ndf commentedTested patch #24 with Drupal commerce (Product entity) and there it works perfectly fine!
I read through the patch-code, but kinda superficial. Code itself looks very clean to me. No typo's or obvious misbehaviours.
What comes to mind that might need review are these edge cases. I didn't see test-coverage for these edge cases.
- Behaviour of bundles without view-modes
- Behaviour of entities without bundles
- Behaviour of bundles/entities with only non-standard view-modes (no full, no teaser)
Comment #26
drunken monkeyThanks a lot for both testing and reviewing, very much appreciated!
I think we can get away with not having automated tests for those special cases – the worst that could happen is that it doesn’t work there and we have to fix and add regression tests – but I’m pretty sure these situations should all be handled fine.
Unfortunately, this now needed a re-roll, but with this it should be RTBC (if the test bot agrees).
Comment #27
borisson_The testbot agrees, and I do as well.
Comment #29
drunken monkeyAwesome, thanks for reviewing!
Committed.
Thanks a lot again, everyone!