alter query view by adding fields in an andGroup within an orGroup
I have a multilanguage site with two languages: English and Dutch. Not all nodes are created in both languages. Some nodes even have no language ('und', 'zxx').
I want the default Drupal provided taxonomy view output all nodes of a taxonomy-term in the current and no node-language, AND, if present, other nodes of this term from the other language. The Drupal provided sql is:
SELECT "taxonomy_index"."sticky" AS "taxonomy_index_sticky", "taxonomy_index"."created" AS "taxonomy_index_created", "node_field_data"."nid" AS "nid", "node_field_data"."langcode" AS "node_field_data_langcode" FROM {node_field_data} "node_field_data" LEFT JOIN {taxonomy_index} "taxonomy_index" ON node_field_data.nid = taxonomy_index.nid WHERE ((taxonomy_index.tid = '14')) AND (("node_field_data"."langcode" IN ('nl', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1')) ORDER BY "taxonomy_index_sticky" DESC, "taxonomy_index_created" DESC LIMIT 11 OFFSET 0I want, if applicable, extend the where clause so it becomes by example:
WHERE (((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1'))) OR (("taxonomy_index"."tid" = '14') AND ("node_field_data"."nid" IN ('43')) AND ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))I wrote a function example_views_query_alter(ViewExecutable $view, QueryPluginBase $query) in which I found out which extra nodes should be added in the extra OR clause. By adding this code:
$group_id = $query->setWhereGroup('OR'); $query->addWhere($group_id, 'taxonomy_index.tid', $tid); $query->addWhere($group_id, 'node_field_data.nid', $missing, 'IN'); $query->addWhere($group_id, 'node_field_data.langcode', $langcodes2, 'NOT IN');But in the extended where clause I get OR instead of AND statements:
WHERE ((taxonomy_index.tid = '14')) AND ((("node_field_data"."langcode" IN ('en', 'und', 'zxx')) AND ("taxonomy_index"."status" = '1')) OR (("taxonomy_index"."tid" = '14') OR ("node_field_data"."nid" IN ('43')) OR ("node_field_data"."langcode" NOT IN ('en', 'und', 'zxx'))))But it should be an AND group within an OR Group, maybe like:
$query->setWhereGroup('OR'); $query->setWhereGroup('AND'); $query->addWhere(...Who can help me out to achive this?