You are here

class CurrentSearchGroup in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 contrib/current_search/plugins/current_search/item_group.inc \CurrentSearchGroup
  2. 7 contrib/current_search/plugins/current_search/item_group.inc \CurrentSearchGroup

Current search item plugin that displays the active facet items in a group.

This plugins displays displays active items grouped by field in a horizontal list.

Hierarchy

Expanded class hierarchy of CurrentSearchGroup

1 string reference to 'CurrentSearchGroup'
current_search_current_search_items in contrib/current_search/current_search.module
Implements hook_current_search_items().

File

contrib/current_search/plugins/current_search/item_group.inc, line 14
The group current search item plugin class.

View source
class CurrentSearchGroup extends CurrentSearchItem {

  /**
   * Implements CurrentSearchItem::execute().
   */
  public function execute(FacetapiAdapter $adapter) {
    $groups = array();

    // Makes sure facet builds are initialized.
    $adapter
      ->processFacets();

    // Adds other current search module's CSS.
    $path = drupal_get_path('module', 'current_search');
    drupal_add_css($path . '/current_search.css');

    // Adds active facets to the current search block.
    $searcher = $adapter
      ->getSearcher();
    foreach ($adapter
      ->getAllActiveItems() as $item) {
      $facet_name = $item['facets'][0];
      $facet_value = $item['value'];
      $groups[$facet_name][$facet_value] = $item;
    }

    // Initializes links attributes, adds rel="nofollow" if configured.
    $attributes = $this->settings['nofollow'] ? array(
      'rel' => 'nofollow',
    ) : array();

    // Gets the translated pattern with token replacements in tact.
    $field_pattern = $this
      ->translate('field_pattern', $this->settings['field_pattern']);

    // Iterates over groups, builds list.
    $build = array();
    foreach ($groups as $facet_name => $group) {
      $items = array();

      // Builds list items.
      foreach ($group as $item) {
        $markup = $adapter
          ->getMappedValue($item['facets'][0], $item['value']);
        $text = empty($markup['#html']) ? check_plain($markup['#markup']) : $markup['#markup'];
        $variables = array(
          'text' => $text,
          'path' => $this
            ->getFacetPath($item, $adapter),
          'options' => array(
            'attributes' => $attributes,
            'html' => TRUE,
            'query' => $this
              ->getQueryString($item, $adapter),
          ),
        );
        $items[] = theme('current_search_link_active', $variables);
      }

      // If there are items, add the render array.
      if ($items) {
        $build[$facet_name]['#theme_wrappers'] = array(
          'current_search_group_wrapper',
        );
        $build[$facet_name]['#id'] = drupal_html_id("current-search-group-{$searcher}-{$this->configName}-{$facet_name}");
        $build[$facet_name]['#facet_name'] = $facet_name;

        // Performs token replacemenets and themes the group title.
        $data = array(
          'facetapi_facet' => facetapi_facet_load($facet_name, $searcher),
        );
        $title = filter_xss(token_replace($field_pattern, $data));
        $build[$facet_name]['title']['#markup'] = theme('current_search_group_title', array(
          'title' => $title,
        ));

        // Builds the list.
        $build[$facet_name]['list'] = array(
          '#theme' => 'item_list',
          '#items' => $items,
          '#attributes' => array(
            'class' => array(
              'inline',
            ),
          ),
        );
      }
    }
    return $build;
  }

  /**
   * Implements CurrentSearchItem::settingsForm().
   */
  public function settingsForm(&$form, &$form_state) {
    $form['field_pattern'] = array(
      '#type' => 'textfield',
      '#title' => t('Field pattern'),
      '#default_value' => $this->settings['field_pattern'],
      '#maxlength' => 255,
      '#description' => t('The pattern of the field label preceeding the links. Token replacement patterns are allowed.'),
    );
    $form['nofollow'] = array(
      '#type' => 'checkbox',
      '#title' => t('Prevent crawlers from following active item links'),
      '#default_value' => $this->settings['nofollow'],
      '#description' => t('Add the <code>rel="nofollow"</code> attribute to active item links to maximize SEO by preventing crawlers from indexing duplicate content and getting stuck in loops.'),
    );

    // Adds token tree.
    $form['tokens'] = $this
      ->getTokenTree(array(
      'facetapi_facet',
    ));
  }

  /**
   * Implements CurrentSearchItem::getDefaultSettings().
   */
  public function getDefaultSettings() {
    return array(
      'field_pattern' => '[facetapi_facet:facet-label]:',
      'nofollow' => 1,
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CurrentSearchGroup::execute public function Implements CurrentSearchItem::execute(). Overrides CurrentSearchItem::execute
CurrentSearchGroup::getDefaultSettings public function Implements CurrentSearchItem::getDefaultSettings(). Overrides CurrentSearchItem::getDefaultSettings
CurrentSearchGroup::settingsForm public function Implements CurrentSearchItem::settingsForm(). Overrides CurrentSearchItem::settingsForm
CurrentSearchItem::$configName protected property The machine readable name of 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 current search item plugin.
CurrentSearchItem::$settings protected property An array of the current search item's 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 the wrapper HTML elements.
CurrentSearchItem::wrapperForm public function Returns form elements that allow users to add wrapper HTML around items.
CurrentSearchItem::__construct public function Constructs a CurrentSearchItem object.