public function FacetapiAdapter::getFacetSettings in Facet API 6.3
Same name and namespace in other branches
- 7.2 plugins/facetapi/adapter.inc \FacetapiAdapter::getFacetSettings()
- 7 plugins/facetapi/adapter.inc \FacetapiAdapter::getFacetSettings()
Returns realm specific settings for a facet.
Parameters
array $facet: An array containing the facet definition.
array $realm: An array containing the realm definition.
Return value
stdClass An object containing the settings.
See also
File
- plugins/
facetapi/ adapter.inc, line 559 - Adapter plugin and adapter related calsses.
Class
- FacetapiAdapter
- Abstract class extended by search backends that retrieves facet information from the database.
Code
public function getFacetSettings(array $facet, array $realm) {
// Builds the unique name of the configuration settings and loads.
$name = $this->info['name'] . ':' . $realm['name'] . ':' . $facet['name'];
if (!isset($this->settings[$name])) {
$this->settings[$name] = $this
->initSettingsObject($name, $facet['name'], $realm['name']);
$is_new = empty($this->settings[$name]->settings);
// Use realm's default widget if facet doesn't define one.
if (!empty($facet['default widget'])) {
$widget = $facet['default widget'];
}
else {
$widget = $realm['default widget'];
}
// Apply default settings.
$this->settings[$name]->settings += array(
'weight' => 0,
'widget' => $widget,
'filters' => array(),
'active_sorts' => array(),
'sort_weight' => array(),
'sort_order' => array(),
'empty_behavior' => 'none',
);
// Apply default sort info if necessary.
if ($is_new) {
$weight = -50;
foreach ($facet['default sorts'] as $sort => $default) {
$this->settings[$name]->settings['active_sorts'][$default[0]] = $default[0];
$this->settings[$name]->settings['sort_weight'][$default[0]] = $weight++;
$this->settings[$name]->settings['sort_order'][$default[0]] = $default[1];
}
}
// Apply the widget plugin's default settings.
$id = $this->settings[$name]->settings['widget'];
$class = ctools_plugin_load_class('facetapi', 'widgets', $id, 'handler');
// If we have an invalid widget, fall back to the realm's default.
if (!$class) {
$id = $this->settings[$name]->settings['widget'] = $realm['default widget'];
$class = ctools_plugin_load_class('facetapi', 'widgets', $id, 'handler');
}
$plugin = new $class($id, $realm, $this
->getFacet($facet), $this->settings[$name]);
$this->settings[$name]->settings += $plugin
->getDefaultSettings();
// @todo Save for performance?
}
return $this->settings[$name];
}