function FacetapiWidgetLinks::settingsForm in Facet API 7.2
Same name and namespace in other branches
- 6.3 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::settingsForm()
- 7 plugins/facetapi/widget_links.inc \FacetapiWidgetLinks::settingsForm()
Overrides FacetapiWidget::settingsForm().
Overrides FacetapiWidget::settingsForm
File
- plugins/
facetapi/ widget_links.inc, line 168 - The facetapi_links and facetapi_checkbox_links widget plugin classes.
Class
- FacetapiWidgetLinks
- Widget that renders facets as a list of clickable links.
Code
function settingsForm(&$form, &$form_state) {
// @see http://drupal.org/node/735528 for supporting multiple values in the
// FAPI #states. The following hack adds multiple form elements and uses CSS
// and JavaScript to ensure only one is displayed at a time. Only the last
// form element actually passes the value.
$form['widget']['widget_settings']['links'][$this->id]['soft_limit'] = array(
'#type' => 'select',
'#title' => t('Soft limit'),
'#default_value' => $this->settings->settings['soft_limit'],
'#options' => array(
0 => t('No limit'),
) + drupal_map_assoc(array(
50,
40,
30,
20,
15,
10,
5,
3,
)),
'#description' => t('Limits the number of displayed facets via JavaScript.'),
'#states' => array(
'visible' => array(
'select[name="widget"]' => array(
'value' => $this->id,
),
),
),
);
// @see http://drupal.org/node/1370342
$form['widget']['widget_settings']['links'][$this->id]['nofollow'] = array(
'#type' => 'checkbox',
'#title' => t('Prevent crawlers from following facet links'),
'#default_value' => !empty($this->settings->settings['nofollow']),
'#description' => t('Add the <code>rel="nofollow"</code> attribute to facet links to maximize SEO by preventing crawlers from indexing duplicate content and getting stuck in loops.'),
'#states' => array(
'visible' => array(
'select[name="widget"]' => array(
'value' => $this->id,
),
),
),
);
// @see http://drupal.org/node/735528
if ($this->facet['hierarchy callback']) {
$form['widget']['widget_settings']['links'][$this->id]['show_expanded'] = array(
'#type' => 'checkbox',
'#title' => t('Expand hierarchy'),
'#default_value' => !empty($this->settings->settings['show_expanded']),
'#description' => t('Show the entire tree regardless of whether the parent items are active.'),
'#states' => array(
'visible' => array(
'select[name="widget"]' => array(
'value' => $this->id,
),
),
),
);
}
// Hides all but the last element. The #states system will override this,
// however it is necessary if JavaScript is disabled so multiple elements
// aren't displayed to the user.
$last = end($form['widget']['widget_settings']['links']);
foreach ($form['widget']['widget_settings']['links'] as $id => $element) {
if ($last != $element) {
$form['widget']['widget_settings']['links'][$id]['#attributes']['style'] = 'display: none;';
}
}
}