diff --git a/draggableviews.module b/draggableviews.module index 0950a5a..19619df 100644 --- a/draggableviews.module +++ b/draggableviews.module @@ -65,7 +65,7 @@ function draggableviews_views_data_alter(&$data) { // Explain to every entity how to join with draggableviews_structure // table. $data['draggableviews_structure']['table']['join'][$base_table] = [ - 'handler' => 'draggableviews_join_handler', + 'join_id' => 'draggableviews_with_args', // Because this is a direct link it could be left out. 'left_table' => $base_table, 'left_field' => $entity_keys['id'], @@ -165,6 +165,7 @@ function draggableviews_views_submit(&$form, FormStateInterface $form_state) { $view = $form_state->getBuildInfo()['args'][0]; $view_name = $view->id(); $view_display = $view->current_display; + $view_args = !empty($view->args) ? json_encode($view->args) : '[]'; $weight = 0; @@ -176,6 +177,7 @@ function draggableviews_views_submit(&$form, FormStateInterface $form_state) { $connection->delete('draggableviews_structure') ->condition('view_name', $view_name) ->condition('view_display', $view_display) + ->condition('args', $view_args) ->condition('entity_id', $item['id']) ->execute(); @@ -183,7 +185,7 @@ function draggableviews_views_submit(&$form, FormStateInterface $form_state) { $record = [ 'view_name' => $view_name, 'view_display' => $view_display, - 'args' => '[]', + 'args' => $view_args, 'entity_id' => $item['id'], 'weight' => $weight, ]; diff --git a/src/Plugin/views/join/WithArgs.php b/src/Plugin/views/join/WithArgs.php new file mode 100644 index 0000000..2311f5d --- /dev/null +++ b/src/Plugin/views/join/WithArgs.php @@ -0,0 +1,47 @@ +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 = []; + } + + if (is_array($this->extra)) { + $found = FALSE; + foreach ($this->extra as $info) { + if (empty(array_diff(array_keys($info), array('field', 'value'))) && $info['field'] == 'args' && $info['value'] == $view_args) { + $found = TRUE; + break; + } + } + + if (!$found) { + $this->extra[] = ['field' => 'args', 'value' => $view_args]; + } + } + + parent::buildJoin($select_query, $table, $view_query); + } +}