123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- function ctools_jump_menu($form, &$form_state, $select, $options = array()) {
- $options += array(
- 'button' => t('Go'),
- 'choose' => t('- Choose -'),
- 'inline' => TRUE,
- 'hide' => TRUE,
- );
- ctools_add_js('jump-menu');
- if (!empty($options['choose'])) {
- $select = array('' => $options['choose']) + $select;
- }
- $form['jump'] = array(
- '#type' => 'select',
- '#options' => $select,
- '#attributes' => array(
- 'class' => array('ctools-jump-menu-select'),
- ),
- );
- if (!empty($options['title'])) {
- $form['jump']['#title'] = $options['title'];
- }
- if (!empty($options['description'])) {
- $form['jump']['#description'] = $options['description'];
- }
- if (!empty($options['default_value'])) {
- $form['jump']['#default_value'] = $options['default_value'];
- }
- if (isset($options['image'])) {
- $form['go'] = array(
- '#type' => 'image_button',
- '#src' => $options['image'],
- '#submit' => array('ctools_jump_menu_submit'),
- '#attributes' => array(
- 'class' => array('ctools-jump-menu-button'),
- ),
- );
- }
- else {
- $form['go'] = array(
- '#type' => 'submit',
- '#value' => $options['button'],
- '#submit' => array('ctools_jump_menu_submit'),
- '#attributes' => array(
- 'class' => array('ctools-jump-menu-button'),
- ),
- );
- }
- if ($options['inline']) {
- $form['jump']['#prefix'] = '<div class="container-inline">';
- $form['go']['#suffix'] = '</div>';
- }
- if ($options['hide']) {
- $form['jump']['#attributes']['class'][] = 'ctools-jump-menu-change';
- $form['go']['#attributes']['class'][] = 'ctools-jump-menu-hide';
- }
- return $form;
- }
- function ctools_jump_menu_submit($form, &$form_state) {
- if ($form_state['values']['jump'] === '') {
-
- return;
- }
-
-
-
- $redirect_array = explode("::", $form_state['values']['jump']);
- if(isset($redirect_array[1]) && !empty($redirect_array[1])){
- $redirect = $redirect_array[1];
- }
- else {
- $redirect = $form_state['values']['jump'];
- }
-
-
-
- $base_path = base_path();
- if (strpos($redirect, $base_path) === 0) {
- $redirect = substr($redirect, strlen($base_path));
- }
-
-
- $redirect = drupal_parse_url($redirect);
- $redirect['path'] = urldecode($redirect['path']);
- $form_state['redirect'] = array($redirect['path'], $redirect);
- }
|