I need to nest some "where Groups" on a QueryPluginBase query, but I can only nest first depth group to the main "where" using setWhereGroup. I need to add groups into another groups but there isn't a function to do it because setWhereGroup let you add a new OR/AND group but I can't set the parent group ID I'd like to nest. For example, I'd need:
((Condition1 OR Condition2) AND ( (Condition3 OR Condicion4) AND (Condition5 OR Condition6) )) OR (Condition7)
This is my custom views filter plugin:
namespace Drupal\my_module\Plugin\views\filter;
use Drupal\views\Plugin\views\filter\FilterPluginBase;
use Drupal\views\Plugin\views\display\DisplayPluginBase;
use Drupal\views\ViewExecutable;
/**
* My custom filter
*
* @ingroup views_filter_handlers
*
* @ViewsFilter("my_custom_filter")
*/
class MyCustomFilter extends FilterPluginBase {
/**
* {@inheritdoc}
*/
public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
parent::init($view, $display, $options);
$this->valueTitle = t('Filtro agendas usuario');
}
public function query() {
$this->query->setWhereGroup('OR', '90');
$user_org = $user->field_usr_org;
foreach ($user_org as $org) {
$this->query->addWhere('90', 'mytable.myfieldid', $org->target_id, '=');
}
$this->query->setWhereGroup('OR', '91');
....
}
}