Hi there,
I'm wondering how you guys add an "- All -" item to your views jump menu's (when using i18n in your website).
The situation:
I have a News Content Type that has to be categorized so I made a News Category Taxonomy. I made a News view with a block in the header of this view that has a jump menu containing all used taxonomies.
The solution:
In a custom module I add this piece of code:
<?php
/**
* Implements hook_form_alter().
*/
function jump_menu_form_alter(&$form, $form_state, $form_id) {
//identify where I need to add - All - button based on path
$jump_menu_indentifier = array('nl/nieuws', 'fr/nouvelles');
//Check if form_id is ctools_jump_menu
if ($form_id == 'ctools_jump_menu') {
foreach($jump_menu_indentifier as $pad) {
//if form action contains our path we defined
if(strpos($form['#action'], $path) !== false) {
//Get all options
$options = $form['jump']['#options'];
//Add - All - button in front that has
$form['jump']['#options'] = array($path => t('- All -')) + $options; ;
}
}
}
}
Only thing I need to do is translate '- All -' in the back-end for all my languages.
This works but does anyone has a better way to achieve this functionality because I don't think this is an error proof way nor is it super dynamic..
Thanks in advance!
Comments
Comment #0.0
f0ns commentedchanged markup, haters gonna hate
Comment #0.1
f0ns commentedextra info
Comment #1
Yuri commentedThanks for the code snippet, I have no alternative solution. Did you?
Comment #2
f0ns commentedStill haven't found a better way to accomplish this, i'm sorry.
Comment #3
renatog commentedHi guys, how are you?
@f0ns, thank you for your request.
For now, your solution works good.
Another way for it creates a Feature Request to create this functionality in views natively.
Comment #4
renatog commentedThank you for your solution.
Any question about it please comment here for us okay?
Best,