For whatever reason, I'm not understanding the *_item method of adding a filter or sort to my default view, and desperately need to in order to finish my project in time for the looming launch date, so I really appreciate any help on this.
To get a head start, I created the view with all of the filters and sorts I would ever need, so I could see their parameters. Then I exported the view into code and cut out all of the filters and sorts from it, so I can add them as needed in my page callback function.
I'm trying to "translate" the override_option method used in the default view code into the *_item method without success.
Here's an example filter from my default view:
$handler->override_option('filters', array(
'type' => array(
'operator' => 'in',
'value' => array(
'ctype1' => 'ctype1',
'ctype2' => 'ctype2',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
// rest of filters
Here's the example code provided by a Views-related information source (http://groups.drupal.org/node/10129):
$display_id = 'default';
$view->set_display($display_id);
$id = $view->add_item($display_id, 'filter', 'og_uid', 'is_admin');
$item = $view->get_item($display_id, 'filter', $id);
$item['value'] = array(0, 1);
$view->set_item($display_id, 'filter', $id, $item);
$view->is_cacheable = FALSE;
If someone would tell me how to replace values in the example code with those in my example filter, then I could probably figure out the rest of my filters and sorts.
Comments
Solved
Thanks to a post in the Views issue queue (http://drupal.org/node/333829), I found the solution.
I did the following:
Note: Since they are not needed in the $options variable, I removed the following parameters from override_option example:
'table' => 'node',
'field' => 'type',
At some point, I may experiment to see if there are other unnecessary options, but for now I'm happy.
Here is my code which I used
Here is my code which I used to filter nodes base on date using embed view via views_get_view().
*Note that the filter is already created on each view with the opperators (less than or equal to).
Developer @ http://www.magicbullet.co.za
Drupal site: http://www.weddingdirectory.co.za
Hi! I was wondering if you
Hi! I was wondering if you could post here in what hook or name of the function did you put these lines of code on adding a filter to an existing view? Would greatly appreciate it. Thanks!
Template Files
Hi Casper,
Sorry for only getting back to you now.
I am sure it is not the correct way of doing it; however, I added the provided code to the template files tpl.php (e.g. page-blabla.tpl.php or node-blabla.tpl.php)
I also used it in mime mail template file (mimemail-message.tpl.php) in order to embed the view into automated emails that are sent on daily basis which is sent using rules (scheduled rules).
You can even go as far as to create a node with php input format and insert the code there.
Hope this helps.
Developer @ http://www.magicbullet.co.za
Drupal site: http://www.weddingdirectory.co.za