You are here

abstract class FacetapiEmptyBehavior in Facet API 7.2

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

Abstract class extended by empty behavior plugins.

Empty behaviors allow administrators to provide alternate facet displays when a facet has no items. The most common use case is displaying a message such as "This facet has no items.".

Hierarchy

Expanded class hierarchy of FacetapiEmptyBehavior

File

plugins/facetapi/empty_behavior.inc, line 15
Base empty behavior plugin class and default implementation.

View source
abstract class FacetapiEmptyBehavior {

  /**
   * The machine readable name of facet configuration.
   *
   * @var string
   */
  protected $configName;

  /**
   * An array of facet settings.
   *
   * This is the the "settings" property of the facet's realm specific settings
   * returned by FacetapiAdapter::getFacetSettings().
   *
   * @var array
   */
  protected $settings;

  /**
   * Constructs a FacetapiEmptyBehavior object.
   *
   * Captures a subset of the facet's settings and applies the plugin defaults.
   *
   * @param stdClass $settings
   *   The facet's realm specific settings as returned by
   *   FacetapiAdapter::getFacetSettings().
   */
  public function __construct(stdClass $settings) {
    $this->configName = $settings->name;
    $this->settings = $settings->settings;
    $this->settings += $this
      ->getDefaultSettings();
  }

  /**
   * Returns the render array used for the facet that is empty, or has no items.
   *
   * @return
   *   The element's render array.
   */
  public abstract function execute();

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

    // Nothing to do...
  }

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

  /**
   * Helper function for translating strings.
   *
   * @param string $key
   *   The array key of the form element under $form['widget']['empty'] in the
   *   facetapi_translate_string() form containing the setting being translated.
   * @param string $string
   *   The string being translated.
   *
   * @return string
   *   The translated string.
   *
   * @see facetapi_translate_string()
   */
  public function translate($key, $string) {
    $config_name = preg_replace('@[^a-zA-Z0-9]@', '_', $this->configName);
    $name = 'facetapi:' . $config_name . ':empty_text:' . $key;
    return facetapi_translate_string($name, $string);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FacetapiEmptyBehavior::$configName protected property The machine readable name of facet configuration.
FacetapiEmptyBehavior::$settings protected property An array of facet settings.
FacetapiEmptyBehavior::execute abstract public function Returns the render array used for the facet that is empty, or has no items. 2
FacetapiEmptyBehavior::getDefaultSettings public function Provides default values for the plugin settings. 1
FacetapiEmptyBehavior::settingsForm public function Allows the plugin to add settings to the display form. 1
FacetapiEmptyBehavior::translate public function Helper function for translating strings.
FacetapiEmptyBehavior::__construct public function Constructs a FacetapiEmptyBehavior object. 1