You are here

abstract class FacetapiFilter in Facet API 7.2

Same name and namespace in other branches
  1. 6.3 plugins/facetapi/filter.inc \FacetapiFilter
  2. 7 plugins/facetapi/filter.inc \FacetapiFilter

Abstract class extended by filter plugins.

Filter plugins are executed in FacetapiFacet::build() after the render array is initialized and before the array is passed to the widget plugin. This allows for runtime data alterations such as hiding active items or only displaying facets in the current level of a hierarchical data set.

Although it is most common to remove items from the render array, it is also possible to add items to the array. However, the filter plugin is executed after FacetapiFacetProcessor::process(), so the hierarchical data has already been processed and index values have already been mapped to their human readable values. If you are looking to add items to the render array that also go through these processes, adding a callback to the facet's "alter callbacks" is probably the best route to take. See hook_facetapi_facet_info() for more information on alter callbacks.

Hierarchy

Expanded class hierarchy of FacetapiFilter

See also

http://drupal.org/node/1156606

File

plugins/facetapi/filter.inc, line 27
Base filter class and core implementations.

View source
abstract class FacetapiFilter {

  /**
   * The machine name of the plugin associated with this instance.
   *
   * @var string
   */
  protected $id;

  /**
   * The adapter associated with facet being filtered.
   *
   * @var FacetapiAdapter
   */
  protected $adapter;

  /**
   * The facet settings.
   *
   * @var stdClass
   */
  protected $settings;

  /**
   * Constructs a FacetapiFilter object.
   *
   * Sets the necessary information required to filter the facet.
   *
   * @param string $id
   *   The machine name of the filter plugin being instantiated as defined in
   *   hook_facetapi_filters() implementations.
   * @param FacetapiAdapter $adapter
   *   The adapter associated with facet being filtered.
   * @param stdClass $settings
   *   The facet's realm specific settings as returned by
   *   FacetapiAdapter::getFacetSettings().
   */
  public function __construct($id, FacetapiAdapter $adapter, stdClass $settings) {
    $this->id = $id;
    $this->adapter = $adapter;
    $this->settings = $settings;
    $this->settings->settings += $this
      ->getDefaultSettings();
  }

  /**
   * Executes the filter by returning an altered render array.
   *
   * @param array $build
   *   The facet's base render array.
   *
   * @return array
   *   The altered render array that will be passed to the widget plugin.
   */
  public abstract function execute(array $build);

  /**
   * Allows the plugin to add settings to the dependency form.
   *
   * @see facetapi_facet_filters_form()
   */
  public function settingsForm(&$form, &$form_state) {

    // Nothing to do.
  }

  /**
   * Provides default values for the plugin settings.
   *
   * All settings added via FacetapiFilter::settingsForm() should have
   * corresponding defaults in this method.
   *
   * @return array
   *   The defaults keyed by setting name to value.
   */
  public function getDefaultSettings() {
    return array();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacetapiFilter::$adapter protected property The adapter associated with facet being filtered.
FacetapiFilter::$id protected property The machine name of the plugin associated with this instance.
FacetapiFilter::$settings protected property The facet settings.
FacetapiFilter::execute abstract public function Executes the filter by returning an altered render array. 2
FacetapiFilter::getDefaultSettings public function Provides default values for the plugin settings.
FacetapiFilter::settingsForm public function Allows the plugin to add settings to the dependency form.
FacetapiFilter::__construct public function Constructs a FacetapiFilter object.