Basic search API integration.
[sandbox/serialjaywalker/1195272.git] / modules / search / includes / facetapi / widget_radios.inc
1 <?php
2
3 /**
4 * @file
5 * The facetapi_links and facetapi_checkbox_links widget plugin classes.
6 */
7
8 /**
9 * Widget that renders facets as a list of clickable links.
10 *
11 * Links make it easy for users to narrow down their search results by clicking
12 * on them. The render arrays use theme_item_list() to generate the HTML markup.
13 */
14 class CommercePOSSearchWidgetRadios extends FacetapiWidget {
15
16 /**
17 * Overrides FacetapiWidget::__construct().
18 */
19 public function __construct($id, array $realm, FacetapiFacet $facet, stdClass $settings) {
20 parent::__construct($id, $realm, $facet, $settings);
21 // $this->jsSettings['limit'] = $this->settings->settings['soft_limit'];
22 $this->key = $facet['name'];
23 }
24
25 /**
26 * Implements FacetapiWidget::execute().
27 *
28 * Transforms the render array into something that can be themed by
29 * theme_item_list().
30 *
31 * @see FacetapiWidgetLinks::setThemeHooks()
32 * @see FacetapiWidgetLinks::buildListItems()
33 */
34 public function execute() {
35 $element = &$this->build[$this->facet['field alias']];
36
37 // Sets each item's theme hook, builds item list.
38 //$this->setThemeHooks($element);
39 $element = array(
40 '#type' => 'radios',
41 '#options' => $this->getOptions($element),
42 '#attributes' => $this->build['#attributes'],
43 '#attached' => array(
44 'js' => array(drupal_get_path('module', 'commerce_pos_search') . '/commerce_pos_search.js' => array()),
45 ),
46 'clear' => array(
47 '#type' => 'markup',
48 '#prefix' => '<a class = \'commerce-pos-search-radios-clear\'>',
49 '#suffix' => '</a>',
50 '#markup' => t('Clear'),
51 '#weight' => 100,
52 ),
53 );
54 //If there's only one option, make sure it's selected.
55 if (count($element['#options']) == 1) {
56 $element['#default_value'] = reset(array_keys($element['#options']));
57 }
58 unset($element['#attributes']['id']);
59 //$element = form_process_radios($element);
60 }
61
62 /**
63 * Get the options for the radio element.
64 *
65 * @param array $build
66 * The items in the facet's render array being transformed.
67 *
68 * @return array
69 * The "items" parameter for theme_item_list().
70 */
71 function getOptions($build) {
72 //$settings = $this->settings->settings;
73 $options = array();
74 // Initializes links attributes, adds rel="nofollow" if configured.
75 $attributes = array('class' => array());
76 $items = array();
77 foreach ($build as $value => $item) {
78 // Adds the facetapi-zero-results class to items that have no results.
79 if ($item['#count']) {
80 $options[$item['#indexed_value']] = $item['#markup'];
81 }
82 }
83
84 return $options;
85 }
86
87 }
88
89