class CurrentSearchItemText in Facet API 7.2
Same name and namespace in other branches
- 6.3 contrib/current_search/plugins/current_search/item_text.inc \CurrentSearchItemText
- 7 contrib/current_search/plugins/current_search/item_text.inc \CurrentSearchItemText
Current search item plugin that displays text configured by the user.
It is a common use case to display the number of results returned by the query or addition to pagination information to end users. This plugin allows administrators to set arbitrary strings with replacement patterns to build the messages they want to display to users in the Current Search block.
Hierarchy
- class \CurrentSearchItem
- class \CurrentSearchItemText
Expanded class hierarchy of CurrentSearchItemText
2 string references to 'CurrentSearchItemText'
- current_search_current_search_items in contrib/
current_search/ current_search.module - Implements hook_current_search_items().
- hook_current_search_items in contrib/
current_search/ current_search.api.php - Define all current search item provided by the module.
File
- contrib/
current_search/ plugins/ current_search/ item_text.inc, line 16 - The text current search item plugin class.
View source
class CurrentSearchItemText extends CurrentSearchItem {
/**
* Implements CurrentSearchItem::execute().
*/
public function execute(FacetapiAdapter $adapter) {
$data = array(
'facetapi_results' => array(
'facetapi_adapter' => $adapter,
),
);
// Determines plurality of string.
if ($this->settings['plural']) {
$condition = '[' . $this->settings['plural_condition'] . ']';
$count = (int) token_replace($condition, $data);
if ($count != 1) {
$raw_text = $this->settings['text_plural'];
$translation_key = 'text_plural';
}
else {
$raw_text = $this->settings['text'];
$translation_key = 'text';
}
}
else {
$raw_text = $this->settings['text'];
$translation_key = 'text';
}
// Translates text, returns themed output.
$translated_text = $this
->translate($translation_key, $raw_text);
$variables = array(
'text' => filter_xss_admin(token_replace($translated_text, $data)),
'wrapper' => $this->settings['wrapper'],
'element' => $this->settings['element'],
'css' => $this->settings['css'],
'class' => current_search_get_classes($this->settings['classes'], $data),
'options' => array(
'html' => TRUE,
),
);
return array(
'#markup' => theme('current_search_text', $variables),
);
}
/**
* Implements CurrentSearchItem::settingsForm().
*/
public function settingsForm(&$form, &$form_state) {
$form['text'] = array(
'#type' => 'textfield',
'#title' => t('Text'),
'#default_value' => $this->settings['text'],
'#maxlength' => 255,
'#description' => t('Custom text displayed in the text box. Token replacement patterns are allowed.'),
);
$form['plural'] = array(
'#type' => 'checkbox',
'#title' => t('Add plural text'),
'#default_value' => $this->settings['plural'],
);
$form['text_plural'] = array(
'#type' => 'textfield',
'#title' => t('Plural text'),
'#default_value' => $this->settings['text_plural'],
'#maxlength' => 255,
'#description' => t('Plural equivalent of the custom text displayed in the text box. Token replacement patterns are allowed.'),
'#states' => array(
'visible' => array(
':input[name="plugin_settings[' . $this->name . '][plural]"]' => array(
'checked' => TRUE,
),
),
),
);
$form['plural_condition'] = array(
'#type' => 'select',
'#title' => t('Plural condition'),
'#options' => array(
'facetapi_results:result-count' => t('Total number of results'),
'facetapi_results:page-number' => t('Page number'),
'facetapi_results:page-limit' => t('Results per page'),
),
'#default_value' => $this->settings['plural_condition'],
'#description' => t('The condition that determines whether the singular or plural string is used.'),
'#states' => array(
'visible' => array(
':input[name="plugin_settings[' . $this->name . '][plural]"]' => array(
'checked' => TRUE,
),
),
),
);
// Adds HTML wrapper elements.
$this
->wrapperForm($form, $form_state);
// Adds token tree.
$form['tokens'] = $this
->getTokenTree(array(
'facetapi_results',
));
}
/**
* Implements CurrentSearchItem::getDefaultSettings().
*/
public function getDefaultSettings() {
$defaults = array(
'plural' => 0,
'plural_condition' => 'facetapi_results:result-count',
'text' => '',
'text_plural' => '',
);
return $defaults + $this
->wrapperDefaults();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CurrentSearchItem:: |
protected | property | The machine readable name of current search block configuration. | |
CurrentSearchItem:: |
protected | property | An array keyed by item position to its value and all its children. | |
CurrentSearchItem:: |
protected | property | The machine readable name of the current search item plugin. | |
CurrentSearchItem:: |
protected | property | An array of the current search item's settings. | |
CurrentSearchItem:: |
public | function | Helper function that returns a facet's path. | |
CurrentSearchItem:: |
public | function | Helper function that returns the item's value and its children. | |
CurrentSearchItem:: |
public | function | Helper function that returns a facet's query string. | |
CurrentSearchItem:: |
public | function | Returns the token tree element. | |
CurrentSearchItem:: |
public | function | Helper function for translating strings. | |
CurrentSearchItem:: |
public | function | Returns defaults for the wrapper HTML elements. | |
CurrentSearchItem:: |
public | function | Returns form elements that allow users to add wrapper HTML around items. | |
CurrentSearchItem:: |
public | function | Constructs a CurrentSearchItem object. | |
CurrentSearchItemText:: |
public | function |
Implements CurrentSearchItem::execute(). Overrides CurrentSearchItem:: |
|
CurrentSearchItemText:: |
public | function |
Implements CurrentSearchItem::getDefaultSettings(). Overrides CurrentSearchItem:: |
|
CurrentSearchItemText:: |
public | function |
Implements CurrentSearchItem::settingsForm(). Overrides CurrentSearchItem:: |