I'm working in a Drupal 9 website.
I need to change operator in my view query from != to <.
In a view i got two contextuals filters:
- The first to retrieve id from an entity reference field.
- The second to retrieve current node id.
In the second contextual filter, exclude is selected to be != in my query.
The result i need is to transform this != to < for show all nodes who got the same reference field ID AND an ID lower than current node id.
It's like a previous Articles by the same reference field!
My view query is :
SELECT "field_entreprises_marque_node_field_data"."created" AS "field_entreprises_marque_node_field_data_created", "node_field_data"."nid" AS "nid", "field_entreprises_marque_node_field_data"."nid" AS "field_entreprises_marque_node_field_data_nid"
FROM
{node_field_data} "node_field_data"
LEFT JOIN {node__field_entreprises_marque} "node__field_entreprises_marque" ON node_field_data.nid = node__field_entreprises_marque.field_entreprises_marque_target_id AND node__field_entreprises_marque.deleted = '0'
LEFT JOIN {node_field_data} "field_entreprises_marque_node_field_data" ON node__field_entreprises_marque.entity_id = field_entreprises_marque_node_field_data.nid
WHERE (("node_field_data"."status" = '1') AND ("node_field_data"."type" IN ('entreprise_marque'))) AND ((node_field_data.nid = '3259' )) AND ((field_entreprises_marque_node_field_data.nid != '22561' OR field_entreprises_marque_node_field_data.nid IS NULL))
ORDER BY "field_entreprises_marque_node_field_data_created" DESC
LIMIT 20 OFFSET 0
What i need is :
field_entreprises_marque_node_field_data.nid < '22561'
I try like this:
use Drupal\views\Plugin\views\query\QueryPluginBase;
use Drupal\views\ViewExecutable;
/**
* Implements hook_views_query_alter().
*/
function mymodule_custom_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
if ($view->current_display === '20_articles_precedents') {
$view->query->where[4]["conditions"][0]["operator"] = '>';
}
}
But nothing appens...