Score:0

How can I use the join handler plugin with groups and multiple conditions?

lb flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.