function FacetapiWidget::sortFacet in Facet API 7
Same name and namespace in other branches
- 6.3 plugins/facetapi/widget.inc \FacetapiWidget::sortFacet()
- 7.2 plugins/facetapi/widget.inc \FacetapiWidget::sortFacet()
Applies sorting algorithms to the items in the facet's render array.
This method applies the sorting algorithms configured via the display form to the items in the facet's initialized render array.
Parameters
array &$build: Reference to the facet's render array.
See also
1 call to FacetapiWidget::sortFacet()
- FacetapiWidget::init in plugins/
facetapi/ widget.inc - Initializes the build, must be invoked prior to executing this widget.
File
- plugins/
facetapi/ widget.inc, line 287 - Base widget plugin class and helper functions for facet sorting.
Class
- FacetapiWidget
- Abstract class extended by widget plugins.
Code
function sortFacet(array &$build) {
$settings = $build['#settings']->settings;
// Gets active sort definitions.
$this->sorts = array_intersect_key(facetapi_get_sort_info(), array_filter($settings['active_sorts']));
// Finalizes sort definitions with settings or defaults.
foreach ($this->sorts as $name => &$info) {
$info['weight'] = $settings['sort_weight'][$name];
$info['order'] = $settings['sort_order'][$name];
}
if ($this->sorts) {
// Orders the sorts, applies sorting algorithms in that order.
uasort($this->sorts, 'drupal_sort_weight');
$this
->applySorts($build[$this->facet['field alias']]);
}
}