Since #1172970: provide a unified way to retrieve result entities we have the possibility to do query-backend agnostic entity-related views fields that work with loaded entity objects provided. Thus, a module can provide a views-field now that works across all backends, but discovery, assignment to the base-tables has still solved manually.
Goal:
A module should be able to provide a views field dedicated to a certain entity-type which then automatically is available regardless of the query-backend used (e.g. search api).
Proposal:
* Add a hook that allows modules to provide views-fields related to entity-types, e.g. hook_views_entity_data()
* Add in that data to the regular views-data dependent on the entity-type.
Comment | File | Size | Author |
---|---|---|---|
#23 | views-entity-related-views-field-1270890-22.patch | 6.79 KB | Blackice2999 |
#22 | views-entity-related-views-field-1270890.patch | 5.85 KB | Blackice2999 |
#17 | views_entity_tables.patch | 4.95 KB | fago |
#15 | views_entity_tables.patch | 4.51 KB | fago |
#13 | views_entity_tables.patch | 4.26 KB | fago |
Comments
Comment #1
fagoalso see the related issue #1266036-1: Add generic Views entity tables with fields and relationships
Comment #2
drunken monkeySubscribing.
The hook would then get
$type
as an argument, right? Sounds reasonable, and shouldn't be too hard, I guess.Comment #3
dawehnerIn general this is a great idea, but i'm wondering just a bit how this should work technically.
If search_api provides general entity data, then for example the node data would have fields both from node_views_data and search_api, which could confuse some users: for example you might have node title + node label, but this is probably just some kind of documentation/labeling issue.
In general after the initial views data collection you could iterate over each table and look for 'entity type' base key and merge the data in, does this make sense? This should work.
Comment #4
fagoThe plan is that search-api does its own base-tables as now, but that those entity-related fields are applied to all base-tables belonging to a certain entity-type. So search-api should not provide its fields that way, but receive some additional entity-related fields via it.
Exactly. However, there is no good timing for doing so, as alterations should be possible too. So having a separate hook + views applying it to the base-tables would be the cleanest way I think. Also that way we could migrate the node edit/delete links to use the hook too.
Comment #5
dawehnerAnother solution instead of the hook is a global "table" like $data['global'] which is joined to each entity table.
So if you show a node or a user you will always see the fields from this entity table.
Comment #6
fagoWell, I think we need per entity-type global tables, thus something like "views_entity_$type". So we can have per-entity-type fields that are available for all base tables that use this entity-type.
But yes, +1 for that approach :)
Comment #7
BenK CreditAttribution: BenK commentedSubscribing
Comment #8
fagoI'll roll a patch for that asap.
Comment #9
jakonore CreditAttribution: jakonore commentedsubscribing
Comment #10
fagoso, finally I've come back to this and rolled the patch - see attached. Works for me.
Added docblock comment should explain how it works.
Comment #11
fagofixed the patch to keep working in case of multiple entity-type tables.. :)
Comment #12
dawehnerIf you define a 'moved' key the fields will work on old views as well.
Comment #13
fagook, I've worked on basing #1209678: Add a Views field handler to display rendered entities and the entity-row plugin upon this. I realized, we also need to add an entity-type to the new views-entity-TYPE tables + initialize $this->entity_type upon init() for the entity-field handler, so one can make use of the entity-type in the options form.
Updated patch attached.
ad #12
How does that work exactly?
Comment #14
tnightingale CreditAttribution: tnightingale commentedsubscribing
Comment #15
fagook, found it myself. Keeps old views using that fields working for me - useful and important feature! :)
Comment #16
clemens.tolboomI'm not sure this is the right issue but I miss an entity related argument.
Say I want to add an local tab on every entity view say node/%/annotate, user/%/annotate taxonomy_term/%/annotate
(My projects issue #1317690: Support annotation for any entity)
Is this issue also about entity arguments? If not should I create one for this?
Comment #17
fagoad #16: nope, please create a separate issue for that.
At #1266036: Add generic Views entity tables with fields and relationships we stumbled over another small issue with the generic entity field handler: It doesn't respect the 'base field' of relationship definitions. That's required to support non-base table entity-tables as we've created over there. I've updated the patch to include this small fix.
Comment #18
fagoFurther improvements:
* Fixed call to get_result_entities() to not pass an additional, unnecessary, undocumented parameter. Looks like an left-over from old code - sry for that.
* Improved get_result_entities() docs based on the docs included in #1266036: Add generic Views entity tables with fields and relationships
Tested re-using the node-link-fields together with #1266036: Add generic Views entity tables with fields and relationships and search api views integration, works great (including relationships)!
Comment #19
mh86 CreditAttribution: mh86 commentedTested patch from #17 with a few scenarios:
All of them worked fine for me and the code looks clean as well.
Comment #20
dawehnerThanks for writing/testing and reviewing the patch!!
Commited to 7.x-3.x
Comment #22
Blackice2999 CreditAttribution: Blackice2999 commentedHi, i am not sure if needed but here additional for user entity
Edit:
ups it seems that all patches was sent for Re-Test ? - If it was wrong to add the patch here please short notify me and next time i open a new issue.
Sorry
Comment #23
Blackice2999 CreditAttribution: Blackice2999 commentedsorry i forget a dpm()
new patch:
Comment #24
dawehnerPart of the code is really similar to what #1859884: Convert user link fields to use entities does.
In a world with a generic views integration using information from the entity storage, would we still use this extra table or would we still use links on the "users" table?
Comment #25
clemens.tolboomRemove this dpm too ;)
Comment #26
fagoThis has been fixed, any follow-up should be filed as a new issue imo.