Disclaimer: This question is merely to collect suggestions, as I solved the problem using an EntityQuery already.
The task: We have an entity that has a title and an additional non-required title alias textfield with unlimited values. So the alias can basically be empty or filled with an unlimited amount of title aliases.
We required a page that lists all titles and alias titles in a single, alphabetically ordered list, where all titles and aliases are linked to the entity where the respective title occurred.
What I tried using Views: To no success, I created a view with two blocks (one for the title, one for the alias field), whereas the fields have been hidden and the links where rendered using a global text field with field tokens. This way, I had two almost similar views (in terms of available fields) with different output.
Each view was doing fine when executed separately; showing the intended results for linked titles in block_1
and linked aliases in block_2
respectively.
Next, I did a query union within hook_views_pre_execute(), hoping to being able to merge both lists:
/** * Implements hook_views_pre_execute(). */ function mymodule_views_pre_execute(ViewExecutable $ view) { if ($ view->id() == 'my_view' && $ view->current_display == 'block_1') { $ view_by_alias = Views::getView('my_view'); $ view_by_alias->build('block_2'); $ query_by_alias = $ view_by_alias->build_info['query']; $ view_index_query = &$ view->build_info['query']; $ view_index_query->union($ query_by_alias); } }
Unfortunately, the global text fields seem to not appear within the query. As both views shared the fields, the above approach resulted in a union of the same query without any differences.
How would I have been able to solve the task by using Views instead of custom programming and using an EntityQuery?