/** * Themes a select drop-down as a collection of links * * @see theme_select(), http://api.drupal.org/api/function/theme_select/6 * @param object $element - An associative array containing the properties of the element. * Properties used: title, value, options, description, name * @return HTML string representing the form element. */ function ciclo20v2_select_as_links($element) { $output = ''; $name = $element['#name']; $selected_options = (array) $element['#post'][$name]; // the selected keys from #options if (empty($_REQUEST[$name])) { $selected_options[] = $element["#{$name}"]; } if (isset($element['#options'])) { foreach ($element['#options'] as $option => $elem) { $multiple = !empty($element['#multiple']); if (array_search($option, $selected_options) === FALSE) { $id = form_clean_id($element['#id'] . '-' . $option); $link = l($elem, bef_replace_query_string_arg($name, $option, $multiple)); $output .= '<li>' . theme('form_element', array('#id' => $id), $link) . '</li>'; } } } $properties = array('#title' => $element['#title'], '#description' => $element['#description']); $inline_js = '$().ready(function() { $("#' . $element['#id'] . 'autocomplete-element").result(function(uno, dos) { link = $(this).parent().parent().find("a:contains(\'" + dos[0] + "\')"); window.location.href = link[0].href; }); })'; drupal_add_js($inline_js, 'inline'); $output = '<ul>' . $output . '</ul>'; return '<div class="bef-select-as-links-special">' . '<div class="bef-select-container">' . '<div class="filter-search"></div>' . '<span class="link-list-title">' . $element['#filter_title'] . '</span>' . theme('form_element', $properties, $output) . '</div></div>'; }
/** * @file * This file is empty by default because the base theme chain (Alpha & Omega) provides * all the basic functionality. However, in case you wish to customize the output that Drupal * generates through Alpha & Omega this file is a good place to do so. * * Alpha comes with a neat solution for keeping this file as clean as possible while the code * for your subtheme grows. Please read the README.txt in the /preprocess and /process subfolders * for more information on this topic. */ function vp_theme_select_as_links($vars) { $element = $vars['element']; $output = ''; $name = $element['#name']; // Collect selected values so we can properly style the links later $selected_options = array(); if (empty($element['#value'])) { if (!empty($element['#default_values'])) { $selected_options[] = $element['#default_values']; } } else { $selected_options[] = $element['#value']; } // Add to the selected options specified by Views whatever options are in the // URL query string, but only for this filter $urllist = parse_url(request_uri()); if (isset($urllist['query'])) { $query = array(); parse_str(urldecode($urllist['query']), $query); foreach ($query as $key => $value) { if ($key != $name) { continue; } if (is_array($value)) { // This filter allows multiple selections, so put each one on the selected_options array foreach ($value as $option) { $selected_options[] = $option; } } else { $selected_options[] = $value; } } } // Clean incoming values to prevent XSS attacks if (is_array($element['#value'])) { foreach ($element['#value'] as $index => $item) { unset($element['#value'][$index]); $element['#value'][filter_xss($index)] = filter_xss($item); } } else { if (is_string($element['#value'])) { $element['#value'] = filter_xss($element['#value']); } } // Go through each filter option and build the appropriate link or plain text foreach ($element['#options'] as $option => $elem) { // Check for Taxonomy-based filters if (is_object($elem)) { $slice = array_slice($elem->option, 0, 1, TRUE); list($option, $elem) = each($slice); } /* * Check for optgroups. Put subelements in the $element_set array and add a group heading. * Otherwise, just add the element to the set */ $element_set = array(); if (is_array($elem)) { $element_set = $elem; } else { $element_set[$option] = $elem; } $links = array(); $multiple = !empty($element['#multiple']); foreach ($element_set as $key => $value) { // Custom ID for each link based on the <select>'s original ID $id = drupal_html_id($element['#id'] . '-' . $key); $elem = array('#id' => $id, '#markup' => '', '#type' => 'bef-link', '#name' => $id); if (array_search($key, $selected_options) === FALSE) { if ($_GET['q'] === 'logo-file') { $elem['#children'] = l($value, 'logo-file/taxonomy', array('query' => array($name => $key))); } elseif ($_GET['q'] === 'medium') { $elem['#children'] = l($value, 'medium/taxonomy', array('query' => array($name => $key))); } else { $elem['#children'] = l($value, bef_replace_query_string_arg($name, $key, $multiple)); } $output .= theme('form_element', array('element' => $elem)); } else { $elem['#children'] = l($value, bef_replace_query_string_arg($name, $key, $multiple, true)); _form_set_class($elem, array('bef-select-as-links-selected')); $output .= str_replace('form-item', 'form-item selected', theme('form_element', array('element' => $elem))); } } } $properties = array('#description' => isset($element['#bef_description']) ? $element['#bef_description'] : '', '#children' => $output); $output = '<div class="bef-select-as-links">'; $output .= theme('form_element', array('element' => $properties)); if (!empty($element['#value'])) { if (is_array($element['#value'])) { foreach ($element['#value'] as $value) { $output .= '<input type="hidden" name="' . $name . '[]" value="' . $value . '" />'; } } else { $output .= '<input type="hidden" name="' . $name . '" value="' . $element['#value'] . '" />'; } } $output .= '</div>'; return $output; }