-2

i want to create a custom block for dropdown list which i can display in all pages.

/*
 *implements hook_menu().
 */

function dropdown_page_menu(){
  $items = array();
  $items['page/layout/%'] = array(
    'title' => 'Select Layout',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('dropdown_page_select_form'),
    'access arguments' => array('access content'),
    );

  return $items;
}

/**
 * Implements hook_theme().
 */

function dropdown_page_theme(){
    return array(
      'dropdown_page_select_form' => array('render element' => 'form',),
      );
}




function dropdown_page_page(){
  $content[] = l(t('select layout'),'page/layout/%');

  return $content;
}

function dropdown_page_select_form($form, &$form_state){
  $options = array(
    'select' => t('Select'),
    'layout_1' => t('Layout 1'),
    'layout_2' => t('Layout 2'),
    'layout_3' => t('Layout 3'),
    );

  $form['choice'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#title' => t('Select your layout'),
    );
  dsm($options);
  $form['submit'] = array(
    '#type' => 'submit',
    '#value'=> t('Go'),
    );
  return $form;
}

function dropdown_page_select_form_submit($form, &$form_state){


switch ($form_state['values']['choice']) {
  case layout_1: {

    //echo 'hi';die;
    drupal_goto("layout_1".$options);
    break;


  }
  case layout_2: {  
    //echo 'no';die;
    drupal_goto("layout_2".$options);
    break;
  }
  case layout_3: {  
    drupal_goto("layout_3".$options);
    break;
  }
  default: {
    print 'Select it!';
  }
}



  drupal_set_message(t('Your layout %input', array('%input' => $form_state['value']['choice'])));
}
3
  • What is your question / problem? Please read 'How to Ask' before asking a question.
    – dayuloli
    Commented Feb 26, 2015 at 7:05
  • 2
    @Nikhil, Welcome to Drupal Answer. Your question seem very unclear. If you can provide details about where you get stuck ? Or what is not working for you ? This would make user to help you answer your question. Commented Feb 26, 2015 at 7:05
  • I'm sorry for my silly questions as i m very new to drupal community and i'm right now on learning stage for custom durpal modules so please forgive me for this. Hope you will help me more in future thank you Commented Feb 26, 2015 at 7:15

1 Answer 1

0

Add code given below to your dropdown_page module, this will create a block which will be visible in blocks list. From blocks section you can assign it to any region you want.

/**
 * Implements hook_block_info().
 */
function dropdown_page_block_info() {
    $blocks = array();

    $blocks['dropdown_page_select_form'] = array(
        'info' => t('Select Layout'),
    );

    return $blocks;
}

/**
 * Implements hook_block_view().
 */
function dropdown_page_block_view($delta = '') {
    $block = array();

    switch ($delta) {
        case 'dropdown_page_select_form':
            $block['subject'] = t('Select Layout');
            $block['content'] = drupal_get_form('dropdown_page_select_form');
            break;
    }

    return $block;
}
0

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.