Exemplo n.º 1
0
 /**
  * Implements FacetapiWidget::execute().
  *
  * We have to hack our way around things to ensure that only one item is
  * active at a time. The downside of this hack is that it might not work with
  * alternate URL processors such as Facet API Pretty Paths. Of course, there
  * is a feature request which I have ignored for some time, so shame on me.
  *
  * @see http://drupal.org/node/1393928
  */
 public function execute()
 {
     $element =& $this->build[$this->facet['field alias']];
     // Get all variables we will need to hack the query string in order to
     // ensure that only one item is active at a time.
     $filter_key = $this->facet->getAdapter()->getUrlProcessor()->getFilterKey();
     $facet = $this->facet->getFacet();
     $field_alias = rawurlencode($facet['field alias']);
     $value_start_pos = strlen($field_alias) + 1;
     // Re-build query string for all date range facets.
     foreach ($element as &$item) {
         // Filters out all other values from the query string excluding the value
         // of the current item.
         if (!$item['#active']) {
             foreach ($item['#query'][$filter_key] as $pos => $filter) {
                 if (0 === strpos($filter, $field_alias . ':')) {
                     $value = substr($filter, $value_start_pos);
                     if ($value !== $item['#indexed_value']) {
                         unset($item['#query'][$filter_key][$pos]);
                     }
                 }
             }
         }
     }
     // Render the links.
     parent::execute();
 }
 /**
  * Implements FacetapiWidget::execute().
  *
  * We have to hack our way around things to ensure that only one item is
  * active at a time. The downside of this hack is that it might not work with
  * alternate URL processors such as Facet API Pretty Paths. Of course, there
  * is a feature request which I have ignored for some time, so shame on me.
  *
  * @see http://drupal.org/node/1393928
  */
 public function execute()
 {
     $element =& $this->build[$this->facet['field alias']];
     // Get all variables we will need to hack the query string in order to
     // ensure that only one item is active at a time.
     $filter_key = $this->facet->getAdapter()->getUrlProcessor()->getFilterKey();
     $facet = $this->facet->getFacet();
     $field_alias = rawurlencode($facet['field alias']);
     $value_start_pos = strlen($field_alias) + 1;
     $processor = $this->facet->getAdapter()->getUrlProcessor();
     $query_params = $processor->getParams();
     // Re-build query string for all date range facets.
     foreach ($element as &$item) {
         // Filters out all other values from the query string excluding the value
         // of the current item.
         if (!$item['#active']) {
             foreach ($query_params[$filter_key] as $filter) {
                 if (0 === strpos($filter, $field_alias . ':')) {
                     $value = substr($filter, $value_start_pos);
                     if ($value !== $item['#indexed_value']) {
                         // FacetApi Pretty Paths url processor.
                         if (get_class($processor) == 'FacetapiUrlProcessorPrettyPaths') {
                             $facet_path_item = str_replace(':', '/', $filter);
                             $item['#path'] = str_replace("/{$facet_path_item}", '', $item['#path']);
                         } else {
                             $num = array_search($filter, $item['#query'][$filter_key]);
                             unset($item['#query'][$filter_key][$num]);
                             // Reset keys.
                             $item['#query'][$filter_key] = array_values($item['#query'][$filter_key]);
                         }
                     }
                 }
             }
         }
         // Always display label for avoid problem from issue #2016601.
         if (!empty($item['label'])) {
             $item['#markup'] = $item['label'];
         }
     }
     // Render the links.
     parent::execute();
 }