Skip to content

Commit 1e731c6

Browse files
Fix error when accessing search page
1 parent 8c49602 commit 1e731c6

File tree

1 file changed

+19
-11
lines changed
  • web/profiles/custom/os2loop/modules/os2loop_user/src/Helper

1 file changed

+19
-11
lines changed

web/profiles/custom/os2loop/modules/os2loop_user/src/Helper/Helper.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\Core\Form\FormStateInterface;
66
use Drupal\Core\Session\AccountInterface;
77
use Drupal\views\ViewExecutable;
8+
use Drupal\views\Plugin\views\query\QueryPluginBase;
89
use Drupal\views\Plugin\views\query\Sql;
910

1011
/**
@@ -27,19 +28,10 @@ public function __construct(AccountInterface $currentUser) {
2728

2829
/**
2930
* Implements hook_views_query_alter().
30-
*
31-
* Change the order of the tables in a LEFT JOIN to preserve NULLs from
32-
* content type.
3331
*/
34-
public function queryAlter(ViewExecutable $view, Sql $query) {
32+
public function queryAlter(ViewExecutable $view, QueryPluginBase $query) {
3533
if ($view->id() === 'os2loop_user_answers') {
36-
$node_table = $query->getTableInfo('node_field_data_comment_field_data');
37-
38-
if (isset($node_table) && $node_table['join']->type === 'LEFT') {
39-
$node_table['join']->type = 'RIGHT';
40-
$query->where[0]['type'] = 'OR';
41-
$query->addWhereExpression(0, 'comment_field_data.uid IS NULL');
42-
}
34+
$this->sqlQueryAlter($view, $query);
4335
}
4436
}
4537

@@ -61,4 +53,20 @@ public function alterForm(array &$form, FormStateInterface $form_state, string $
6153
}
6254
}
6355

56+
/**
57+
* Helper function for SQL queries.
58+
*
59+
* Change the order of the tables in a LEFT JOIN to preserve NULLs from
60+
* content type.
61+
*/
62+
private function sqlQueryAlter(ViewExecutable $view, Sql $query) {
63+
$node_table = $query->getTableInfo('node_field_data_comment_field_data');
64+
65+
if (isset($node_table) && $node_table['join']->type === 'LEFT') {
66+
$node_table['join']->type = 'RIGHT';
67+
$query->where[0]['type'] = 'OR';
68+
$query->addWhereExpression(0, 'comment_field_data.uid IS NULL');
69+
}
70+
}
71+
6472
}

0 commit comments

Comments
 (0)