I'm trying to build a custom view filter and in the query method I need to create this 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'))
Using the documentation for ViewsJoinHandler
, I was able to create the join, but I couldn't recreate the conditionals in the "extra" property as the documentation suggested.
$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);
Is it possible to add to the "extra" the conditions as the original query in the way shown in the documentation, respecting the parentheses and the OR condition?
$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 I can add an OR between two conditions or parentheses to group some.