I’m trying to build a custom view filter and in the query method I need to create the next JOIN:
LEFT JOIN node__field_list list ON node_field_data.nid = list.entity_id AND list.deleted = 0 AND (list.langcode = node_field_data.langcode OR list.bundle IN ('option_1','option_2'))
Then using the documentation ViewsJoinHandler I was able to create the join (and works perfectly) BUT I couldn’t recreate the conditionals in the "extra" property as the documentation suggested. This is how looks my join:
$table = 'node_field_data'; $related_content = ['option_1','option_2']; $extra = "cc.deleted = 0 AND (cc.langcode = node_field_data.langcode OR cc.bundle IN ('" . implode("','", $related_content) . "'))"; $join_definition = [ 'table' => 'node__field_list', 'field' => 'entity_id', 'left_table' => $table, 'left_field' => 'nid', 'operator' => '=', 'extra' => $extra, ]; $join = Views::pluginManager('join')->createInstance('standard', $join_definition); $this->query->addRelationship('cc', $join, $table);
So, I want to know if is possible to add to the "extra" the conditions as the original Query but using the way shown in the documentation, respecting the parentheses and the OR condition, something like this (looks better):
$table = 'node_field_data'; $related_content = ['option_1','option_2']; $join_definition = [ 'table' => 'node__field_list', 'field' => 'entity_id', 'left_table' => $table, 'left_field' => 'nid', 'operator' => '=', 'extra' => [ [ 'field' => 'deleted', 'value' => 0, ], [ 'field' => 'langcode', 'left_field' => 'langcode', ], [ 'field' => 'bundle', 'value' => $related_content, 'operator' => 'IN', ], ], ];
The last join adds only AND conditions for each element in the ‘extra’ array, but I don’t know how can I add an OR between two conditions or parentheses to group some. Thanks