WithArgs.php in DraggableViews 2.0.x
File
src/Plugin/views/join/WithArgs.php
View source
<?php
namespace Drupal\draggableviews\Plugin\views\join;
use Drupal\draggableviews\Plugin\views\sort\DraggableViewsSort;
use Drupal\views\Plugin\views\join\JoinPluginBase;
use Drupal\views\ViewExecutable;
class WithArgs extends JoinPluginBase {
public function buildJoin($select_query, $table, $view_query) {
$view = $view_query->view;
$view_args = !empty($view_query->view->args) ? $view_query->view->args : [];
$context = [
'select_query' => &$select_query,
'table' => &$table,
'view_query' => &$view_query,
];
\Drupal::moduleHandler()
->alter('draggableviews_join_withargs', $view_args, $context);
$view_args = json_encode($view_args);
if (!isset($this->extra)) {
$this->extra = [];
}
$includeArgs = true;
$sort = $view->sort ?? [];
foreach ($sort as $sortClass) {
if ($sortClass instanceof DraggableViewsSort) {
$pass = $sortClass->options['draggable_views_pass_arguments'] ?? 0;
if (empty($pass) || $pass === '0') {
$includeArgs = false;
}
}
}
if (is_array($this->extra)) {
$found = FALSE;
foreach ($this->extra as $info) {
if (empty(array_diff(array_keys($info), [
'field',
'value',
])) && $info['field'] == 'args' && $info['value'] == $view_args) {
$found = TRUE;
break;
}
}
if (!$found && $includeArgs) {
$this->extra[] = [
'field' => 'args',
'value' => $view_args,
];
}
}
parent::buildJoin($select_query, $table, $view_query);
}
}
Classes
Name |
Description |
WithArgs |
Defines a join handler with arguments. |