You are here

class FacetapiEmptyBehaviorText in Facet API 6.3

Same name and namespace in other branches
  1. 7.2 plugins/facetapi/empty_behavior_text.inc \FacetapiEmptyBehaviorText
  2. 7 plugins/facetapi/empty_behavior_text.inc \FacetapiEmptyBehaviorText

Returns text.

Hierarchy

Expanded class hierarchy of FacetapiEmptyBehaviorText

1 string reference to 'FacetapiEmptyBehaviorText'
facetapi_facetapi_empty_behaviors in ./facetapi.facetapi.inc
Implements hook_facetapi_empty_behaviors().

File

plugins/facetapi/empty_behavior_text.inc, line 11
Empty behavior that returns text.

View source
class FacetapiEmptyBehaviorText extends FacetapiEmptyBehavior {

  /**
   * A boolean flagging whether the input format is set, FALSE means it is
   * being pulled from FacetapiEmptyBehavior::getDefaultSettings().
   */
  protected $formatSet = FALSE;

  /**
   * Checks if a format was selected, calls parent's constructor.
   */
  public function __construct(stdClass $settings) {
    if (isset($settings->settings['empty_text_format'])) {
      $this->formatSet = TRUE;
    }
    parent::__construct($settings);
  }

  /**
   * Returns an empty array.
   */
  public function execute() {
    $format_id = $this->settings['empty_text_format'];
    $text = $this
      ->translate('empty_text', $this->settings['empty_text']);
    return check_markup($text, $format_id);
  }

  /**
   * Adds setting for the empty behavior.
   */
  public function settingsForm(&$form, &$form_state) {
    global $user;
    $format_id = filter_resolve_format($this->formatSet ? $this->settings['empty_text_format'] : FILTER_FORMAT_DEFAULT);
    $format = filter_format_load($format_id);

    // NOTE: There is a core bug with form #states and the text_format #type.
    // @see http://drupal.org/node/997826
    $form['widget']['empty']['empty_text'] = array(
      '#type' => 'textarea',
      '#access' => $format && filter_access($format, $user),
      '#title' => t('Empty text'),
      '#default_value' => $this->settings['empty_text'],
    );
    $form['widget']['empty']['empty_text_format'] = filter_form($format_id);
  }

  /**
   * Returns an array of default settings.
   */
  public function getDefaultSettings() {
    return array(
      'empty_text' => '',
      'empty_text_format' => FILTER_FORMAT_DEFAULT,
    );
  }

}

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::translate public function Helper function for translating strings.
FacetapiEmptyBehaviorText::$formatSet protected property A boolean flagging whether the input format is set, FALSE means it is being pulled from FacetapiEmptyBehavior::getDefaultSettings().
FacetapiEmptyBehaviorText::execute public function Returns an empty array. Overrides FacetapiEmptyBehavior::execute
FacetapiEmptyBehaviorText::getDefaultSettings public function Returns an array of default settings. Overrides FacetapiEmptyBehavior::getDefaultSettings
FacetapiEmptyBehaviorText::settingsForm public function Adds setting for the empty behavior. Overrides FacetapiEmptyBehavior::settingsForm
FacetapiEmptyBehaviorText::__construct public function Checks if a format was selected, calls parent's constructor. Overrides FacetapiEmptyBehavior::__construct