2

I am using Drupal 7 and CTools. I want to create a jump menu using Ctools. I have checked the example code provided in the Ctools module. And it is working fine for one link only.

How do I add more links in Jump menu:

In the code shown below, look at here: $url = url('mypostings/groupsort'); I want to add more links in the jump menu,like url('mypostings/test1'), url('mypostings/test2') etc..

/**
 * Implementation of hook_menu();
 * @return 
 */
function post_display_menu() {
    $items['mypostings'] = array(
            'title' => 'My Posts in Group',
            'page callback' => 'get_my_postings',
            'access callback' => TRUE,
            'expanded' => TRUE,
    );
    $items['mypostings/groupsort'] = array(
            'title' => 'My Postings Filter',
            'page callback' => 'get_my_posting_filter',
            'access arguments' => array('access simple page'),
    );
    return $items;
}

function get_my_postings() {
    global $user;
    // Include the CTools tools that we need.
    ctools_include('ajax');
    ctools_include('modal');
    // Add CTools' javascript to the page.
    ctools_modal_add_js();
    $header = array(
            array('data' => t('Title'), 'field' => 'n.title'),
            array('data' => t('Created'), 'field' => 'n.created'),
            array('data' => t('Author'), 'field' => 'u.name'),
    );
    $query = db_select('node', 'n');
    $query->leftjoin('users', 'u', 'u.uid = n.uid');
    $query->fields('n',array('title', 'created'))
    ->fields('u',array('name'))
    ->groupBy('n.nid');
    $result = $query->execute();
    $rows = array();
    foreach ($result as $row) {
        $rows[] = array('data' => (array) $row);
    }
    $build['tablesort_table'] = array(
            '#theme' => 'table',
            '#header' => $header,
            '#rows' => $rows,
    );

    drupal_add_js($sample_style, 'setting');


    ctools_add_js('ctools-ajax-sample', 'ctools_ajax_sample');
    ctools_add_css('ctools-ajax-sample', 'ctools_ajax_sample');

    $output .= $build;

    // Create a jump menu
    ctools_include('jump-menu');
    $form = drupal_get_form('post_filter_jump_menu_form');
    $output .= '<h3>'. t('Jump Menu') .'</h3>';
    $output .= drupal_render($form);

    return array('markup' => array('#markup' => $output));
    return $build;
}

/**
 * Helper function to provide a sample jump menu form
 */
function ctools_ajax_sample_jump_menu_form() {
    $url = url('mypostings/groupsort'); // I want to add 3 links in jump menu How can i add it
    $form_state = array();
    $form = ctools_jump_menu(array(), $form_state, array($url => t('Sort')), array());
    return $form;
}

1 Answer 1

2

See below code !

$form = ctools_jump_menu(array(), $form_state, array($url => t('Jump!') , 'http://www.google.com' => 'Go to google'), array());

OR

$options = array();
$options[$url1] = $label1;
$options[$url2] = $label2;
$form = ctools_jump_menu(array(), $form_state, $options, array());

Third argument of ctools_jump_menu is $select which is

An array suitable for use as the #options. The keys will be the direct URLs that will be jumped to, so you absolutely must encode these using url() in order for them to work reliably.

5
  • 1
    already Done dude.. and upvoted too Oct 23, 2012 at 7:10
  • @mohit_rocks slightly off-topic, but I think you should read this ;)
    – AjitS
    Oct 23, 2012 at 7:27
  • @indrock there are various meanings in wikipedia, In the early 1960s, dude became prominent in surfer culture as a synonym of "guy"., which i wanted to tell Oct 23, 2012 at 7:36
  • @indrock by the way are you from Pune ? Oct 23, 2012 at 7:36
  • @mohit_rocks yes :)
    – AjitS
    Oct 23, 2012 at 7:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.