build[$this->facet['field alias']]; $theme_suffix = ''; $theme_suffix .= '__' . preg_replace('/\W+/', '_', $this->facet->getAdapter()->getSearcher()); $theme_suffix .= '__' . preg_replace('/\W+/', '_', $this->facet['field alias']); $element = array( '#theme' => 'search_api_ranges_slider' . $theme_suffix, '#slider' => $this->_buildUIDateForm(), ); } /** * Allows the widget to provide additional settings to the form. */ function settingsForm(&$form, &$form_state) { $form['widget']['widget_settings']['links'][$this->id]['date_format'] = array( '#type' => 'textfield', '#title' => t('Date format'), '#default_value' => $this->settings->settings['date_format'], '#description' => t('A user-defined date format. See the PHP manual for available options.', array('@url' => 'http://php.net/manual/fr/function.date.php')), '#states' => array('visible' => array('select[name="widget"]' => array('value' => $this->id),),), ); } /** * Returns defaults for the settings form. */ function getDefaultSettings() { return array( 'date_format' => 'Y-m-d', ); } /** * Builds a UI slider themed form. * Performs min/max queries through Search API. */ public function _buildUIDateForm() { // Get Search API stuff $searcher = $this->facet->getAdapter()->getSearcher(); $index_id = explode('@', $searcher); $index = search_api_index_load($index_id[1]); list($query, $results) = $this->facet->getAdapter()->getCurrentSearch(); // Make a clone of the query, as to not alter the current search query $query = clone $query; // Prepare variables $variables = array( 'index' => $index, 'range_field' => $this->facet['field alias'], 'query' => $query, ); // Get facet path field/alias $range_field = $this->facet['field alias']; if (module_exists('facetapi_pretty_paths')) { $processor = new FacetapiUrlProcessorPrettyPaths($this->facet->getAdapter()); $range_field = $processor->getFacetPrettyPathsAlias($this->facet->getFacet()); }; // Prepare the theme variables and return themed form // @see search-api-ranges-slider.tpl.php $variables = array( 'range_field' => rawurlencode($range_field), 'date_format' => $this->settings->settings['date_format'], 'active_items' => $this->facet->getAdapter()->getAllActiveItems(), 'target' => $this->facet->getAdapter()->getSearchPath(), ); // We need to generate unique form IDs in case multiple forms get rendered // on the same page. search_api_ranges_forms() takes care of mapping them // back to the base form ID 'search_api_ranges_block_date_view_form'. return drupal_get_form('search_api_ranges_block_date_view_form_' . $range_field, $variables); } }