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

f0ns’s picture

Issue summary: View changes

changed markup, haters gonna hate

f0ns’s picture

Issue summary: View changes

extra info

Yuri’s picture

Thanks for the code snippet, I have no alternative solution. Did you?

f0ns’s picture

Still haven't found a better way to accomplish this, i'm sorry.

renatog’s picture

Hi 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.

renatog’s picture

Status: Active » Fixed

Thank you for your solution.

Any question about it please comment here for us okay?

Best,

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.