public function FacetapiWidget::init in Facet API 7
Same name and namespace in other branches
- 6.3 plugins/facetapi/widget.inc \FacetapiWidget::init()
- 7.2 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 should 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();
// Prepare the title
$title = $this->facet['label'];
$title_override = isset($this->settings->settings['title_override']) && !empty($this->settings->settings['title_override']);
if ($title_override) {
$title = $this->settings->settings['title'];
if (module_exists('i18n_string')) {
$title = facetapi_i18n_string_translate('facetapi:title_text:' . $title . ':text', $title);
}
}
// Initialize the render array.
$this->build = array(
'#title' => $title,
'#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);
// Translate the "Show more/fewer" links if the String Translation module is
// enabled.
$show_more_text = $this->settings->settings['facet_more_text'];
$show_fewer_text = $this->settings->settings['facet_fewer_text'];
if (module_exists('i18n_string')) {
$show_more_text = facetapi_i18n_string_translate('facetapi:link_text:' . $show_more_text . ':text', $show_more_text);
$show_fewer_text = facetapi_i18n_string_translate('facetapi:link_text:' . $show_fewer_text . ':text', $show_fewer_text);
}
// 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' => $show_more_text,
'showFewerText' => $show_fewer_text,
);
return $this;
}