public function FacetapiWidget::init in Facet API 7.2
Same name and namespace in other branches
- 6.3 plugins/facetapi/widget.inc \FacetapiWidget::init()
- 7 plugins/facetapi/widget.inc \FacetapiWidget::init()
Initializes the build, must be invoked prior to executing this widget.
This method is called automatically by FacetapiFacet::build() and shoud rarely be invoked outside of that context. It is responsible for getting the base render array stored in the FacetapiFacet object and appending it to the container that will be returned, sorting the facets, and adding some common JavaScript settings common across all widgets.
Return value
FacetapiWidget An instance of this class.
1 call to FacetapiWidget::init()
- FacetapiWidgetCheckboxLinks::init in plugins/
facetapi/ widget_links.inc - Overrides FacetapiWidgetLinks::init().
1 method overrides FacetapiWidget::init()
- FacetapiWidgetCheckboxLinks::init in plugins/
facetapi/ widget_links.inc - Overrides FacetapiWidgetLinks::init().
File
- plugins/
facetapi/ widget.inc, line 124 - Base widget plugin class and helper functions for facet sorting.
Class
- FacetapiWidget
- Abstract class extended by widget plugins.
Code
public function init() {
// Capture searcher for code readability.
$searcher = $this->facet
->getAdapter()
->getSearcher();
// Initialize the render array.
$this->build = array(
'#title' => $this->facet['label'],
'#description' => $this->facet['description'],
'#weight' => $this->facet['weight'],
'#adapter' => $this->facet
->getAdapter(),
'#realm_name' => $this->realm['name'],
'#facet' => $this->facet
->getFacet(),
'#settings' => $this->settings,
$this->facet['field alias'] => $this->facet
->getBuild(),
'#attributes' => array(
'class' => array(
drupal_html_class("facetapi-" . $this->id),
drupal_html_class("facetapi-facet-{$this->facet['name']}"),
),
'id' => drupal_html_id("facetapi-facet-{$searcher}-{$this->realm['name']}-{$this->facet['name']}"),
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'facetapi') . '/facetapi.js',
),
),
);
// Apply sorting algorithms to the render array.
$this
->sortFacet($this->build);
// Initialize JavaScript settings for this facet build.
$this->jsSettings += array(
'id' => $this->build['#attributes']['id'],
'searcher' => $searcher,
'realmName' => $this->realm['name'],
'facetName' => $this->facet['name'],
'queryType' => $this->facet['query type'],
'widget' => $this->settings->settings['widget'],
'showMoreText' => $this->settings->settings['facet_more_text'],
'showFewerText' => $this->settings->settings['facet_fewer_text'],
);
return $this;
}