How to override pupal view pager request?

I use drupal 6 and watch 2 -

I created my own filter for my presentation using this documentation

http://www.chadcf.com/blog/creating-custom-filters-drupal-and-views .

Everything seems to work fine, only one problem -

My pagination does not work (not displayed with some operator)

Let me explain what I want to do briefly -

In my pageview, I already have some kind of open filter with a drop-down list of operators, and I created one custom open filter without a drop-down operator.

My requirement is to combine one existing filter function with my custom filter. So, two filters will work together to achieve the desired result. But one filter consists of an existing field, and if I select any of its operators from the drop-down list, this value is included in the where clause, which I do not want. So I completely removed the request piece from the view request with

hook_views_pre_execute(&$view) { $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']); } 

Now in my sites / all / modules / mymodule / on / mymodule_filter.inc

 function query() { $this->query->add_where($this->options['group'], "MY_QUERY"); } 

which add a where clause to view the request.

Using the above procedure, I have successfully expanded the default behavior of the view, and also got the desired result, but for some link to pagination does not appear even I know that there are more records in the database.

I know why this is happening because my view of the script does not know the changes I made.

My question is: HOW CAN I APPEAL TO VIEW THE QUESTION?

Any help would be greatly appreciated.

+4
source share
1 answer

What did I do to remove the where clause from a query of the form below.

 hook_views_pre_execute(&$view) { $view->build_info['query'] = preg_replace('/AND \(node_data_field_stock.field_stock_value [<<=>>=!=\\s%d|IS NULL|IS NOT NULL]*\)/','',$view->build_info['query']); } 

But the correct place to delete the where clause that you want to remove from the view request is hook_views_query_alter (). Using this tutorial

http://www.drupaler.co.uk/blog/altering-views-query-tackling-node-type-filter-bug/451

  function hook_views_query_alter(&$view, &$query) { if($view->name == 'view_name'){ var_dump($query->where[0]['clauses']); foreach ($query->where[0]['clauses'] as $key=>$value) { if(preg_match('/node_data_field_stock.field_stock_value/',$value)){ unset($query->where[0]['clauses'][$key]); // remove the where clause by it key } } var_dump($query->where[0]['clauses']); } } 
+4
source

Source: https://habr.com/ru/post/1384668/


All Articles