You are here

class CurrentSearchItemText in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 contrib/current_search/plugins/current_search/item_text.inc \CurrentSearchItemText
  2. 7 contrib/current_search/plugins/current_search/item_text.inc \CurrentSearchItemText

Extension of CurrentSearchItem that displays all active items.

Hierarchy

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 11
Plugin that adds custom text to the current search block.

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, 'facetapi_results', $adapter);
      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, 'facetapi_results', $adapter)),
      '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(
      '#value' => 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' => 'result-count',
      'text' => '',
      'text_plural' => '',
    );
    return $defaults + $this
      ->wrapperDefaults();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentSearchItem::$configName protected property The machine readable name of the current search block configuration.
CurrentSearchItem::$itemValues protected property An array keyed by item position to its value and all its children.
CurrentSearchItem::$name protected property The machine readable name of the item this instance is associated with.
CurrentSearchItem::$settings protected property An array of facet settings.
CurrentSearchItem::getFacetPath public function Helper function that returns a facet's path.
CurrentSearchItem::getItemValues public function Helper function that returns the item's value and its children.
CurrentSearchItem::getQueryString public function Helper function that returns a facet's query string.
CurrentSearchItem::getTokenTree public function Returns the token tree element.
CurrentSearchItem::translate public function Helper function for translating strings.
CurrentSearchItem::wrapperDefaults public function Returns defaults for "wrapper HTML" elements.
CurrentSearchItem::wrapperForm public function Returns "wrapper HTML" form elements.
CurrentSearchItem::__construct public function Constructs a CurrentSearchItem object.
CurrentSearchItemText::execute public function Implements CurrentSearchItem::execute(). Overrides CurrentSearchItem::execute
CurrentSearchItemText::getDefaultSettings public function Implements CurrentSearchItem::getDefaultSettings(). Overrides CurrentSearchItem::getDefaultSettings
CurrentSearchItemText::settingsForm public function Implements CurrentSearchItem::settingsForm(). Overrides CurrentSearchItem::settingsForm