danielebarchiesi@0: t('Go'),
danielebarchiesi@0: 'choose' => t('- Choose -'),
danielebarchiesi@0: 'inline' => TRUE,
danielebarchiesi@0: 'hide' => TRUE,
danielebarchiesi@0: );
danielebarchiesi@0:
danielebarchiesi@0: ctools_add_js('jump-menu');
danielebarchiesi@0:
danielebarchiesi@0: if (!empty($options['choose'])) {
danielebarchiesi@0: $select = array('' => $options['choose']) + $select;
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: $form['jump'] = array(
danielebarchiesi@0: '#type' => 'select',
danielebarchiesi@0: '#options' => $select,
danielebarchiesi@0: '#attributes' => array(
danielebarchiesi@0: 'class' => array('ctools-jump-menu-select'),
danielebarchiesi@0: ),
danielebarchiesi@0: );
danielebarchiesi@0:
danielebarchiesi@0: if (!empty($options['title'])) {
danielebarchiesi@0: $form['jump']['#title'] = $options['title'];
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: if (!empty($options['description'])) {
danielebarchiesi@0: $form['jump']['#description'] = $options['description'];
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: if (!empty($options['default_value'])) {
danielebarchiesi@0: $form['jump']['#default_value'] = $options['default_value'];
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: if (isset($options['image'])) {
danielebarchiesi@0: $form['go'] = array(
danielebarchiesi@0: '#type' => 'image_button',
danielebarchiesi@0: '#src' => $options['image'],
danielebarchiesi@0: '#submit' => array('ctools_jump_menu_submit'),
danielebarchiesi@0: '#attributes' => array(
danielebarchiesi@0: 'class' => array('ctools-jump-menu-button'),
danielebarchiesi@0: ),
danielebarchiesi@0: );
danielebarchiesi@0: }
danielebarchiesi@0: else {
danielebarchiesi@0: $form['go'] = array(
danielebarchiesi@0: '#type' => 'submit',
danielebarchiesi@0: '#value' => $options['button'],
danielebarchiesi@0: '#submit' => array('ctools_jump_menu_submit'),
danielebarchiesi@0: '#attributes' => array(
danielebarchiesi@0: 'class' => array('ctools-jump-menu-button'),
danielebarchiesi@0: ),
danielebarchiesi@0: );
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: if ($options['inline']) {
danielebarchiesi@0: $form['jump']['#prefix'] = '
';
danielebarchiesi@0: $form['go']['#suffix'] = '
';
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: if ($options['hide']) {
danielebarchiesi@0: $form['jump']['#attributes']['class'][] = 'ctools-jump-menu-change';
danielebarchiesi@0: $form['go']['#attributes']['class'][] = 'ctools-jump-menu-hide';
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: return $form;
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: /**
danielebarchiesi@0: * Submit handler for the jump menu.
danielebarchiesi@0: *
danielebarchiesi@0: * This is normally only invoked upon submit without javascript enabled.
danielebarchiesi@0: */
danielebarchiesi@0: function ctools_jump_menu_submit($form, &$form_state) {
danielebarchiesi@0: if ($form_state['values']['jump'] === '') {
danielebarchiesi@0: // We have nothing to do when the user has not selected any value.
danielebarchiesi@0: return;
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: // If the path we are redirecting to contains the string :: then treat the
danielebarchiesi@0: // the string after the double colon as the path to redirect to.
danielebarchiesi@0: // This allows duplicate paths to be used in jump menus for multiple options.
danielebarchiesi@0: $redirect_array = explode("::", $form_state['values']['jump']);
danielebarchiesi@0:
danielebarchiesi@0: if(isset($redirect_array[1]) && !empty($redirect_array[1])){
danielebarchiesi@0: $redirect = $redirect_array[1];
danielebarchiesi@0: }
danielebarchiesi@0: else {
danielebarchiesi@0: $redirect = $form_state['values']['jump'];
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: // If the path we are redirecting to starts with the base path (for example,
danielebarchiesi@0: // "/somepath/node/1"), we need to strip the base path off before passing it
danielebarchiesi@0: // to $form_state['redirect'].
danielebarchiesi@0: $base_path = base_path();
danielebarchiesi@0: if (strpos($redirect, $base_path) === 0) {
danielebarchiesi@0: $redirect = substr($redirect, strlen($base_path));
danielebarchiesi@0: }
danielebarchiesi@0:
danielebarchiesi@0: // Parse the URL so that query strings and fragments are preserved in the
danielebarchiesi@0: // redirect.
danielebarchiesi@0: $redirect = drupal_parse_url($redirect);
danielebarchiesi@0: $redirect['path'] = urldecode($redirect['path']);
danielebarchiesi@0: $form_state['redirect'] = array($redirect['path'], $redirect);
danielebarchiesi@0: }