You are here

abstract class SearchApiAutocompleteSuggesterPluginBase in Search API Autocomplete 7

Provides a base class for suggester plugins.

Hierarchy

Expanded class hierarchy of SearchApiAutocompleteSuggesterPluginBase

See also

SearchApiAutocompleteSuggesterInterface

hook_search_api_autocomplete_suggester_info()

File

src/SearchApiAutocompleteSuggesterPluginBase.php, line 14
Contains SearchApiAutocompleteSuggesterPluginBase.

View source
abstract class SearchApiAutocompleteSuggesterPluginBase implements SearchApiAutocompleteSuggesterInterface {

  /**
   * The search this suggester is attached to.
   *
   * @var SearchApiAutocompleteSearch
   */
  protected $search;

  /**
   * The suggester plugin's ID.
   *
   * @var string
   */
  protected $pluginId;

  /**
   * The suggester plugin's definition.
   *
   * @var array
   */
  protected $pluginDefinition = array();

  /**
   * The suggester plugin's configuration.
   *
   * @var array
   */
  protected $configuration = array();

  /**
   * {@inheritdoc}
   */
  public static function create(SearchApiAutocompleteSearch $search, array $configuration, $plugin_id, array $plugin_definition) {

    // It seems there is no way to have "new static()"-like functionality in
    // PHP 5.2, so we have to use this workaround instead.
    $class = $plugin_definition['class'];
    return new $class($search, $configuration, $plugin_id, $plugin_definition);
  }

  /**
   * {@inheritdoc}
   */
  public static function supportsIndex(SearchApiIndex $index) {
    return TRUE;
  }

  /**
   * Constructs a SearchApiAutocompleteSuggesterPluginBase.
   *
   * @param SearchApiAutocompleteSearch $search
   *   The search to which this suggester is attached.
   * @param array $configuration
   *   An associative array containing the suggester's configuration, if any.
   * @param string $plugin_id
   *   The suggester's plugin ID.
   * @param array $plugin_definition
   *   The suggester plugin's definition.
   */
  public function __construct(SearchApiAutocompleteSearch $search, array $configuration, $plugin_id, array $plugin_definition) {
    $this->search = $search;
    $this->pluginId = $plugin_id;
    $this->pluginDefinition = $plugin_definition;
    $this
      ->setConfiguration($configuration);
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginId() {
    return $this->pluginId;
  }

  /**
   * {@inheritdoc}
   */
  public function getPluginDefinition() {
    return $this->pluginDefinition;
  }

  /**
   * {@inheritdoc}
   */
  public function getSearch() {
    return $this->search;
  }

  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->pluginDefinition['label'];
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return isset($this->pluginDefinition['description']) ? $this->pluginDefinition['description'] : NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration + $this
      ->defaultConfiguration();
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function defaultConfiguration() {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, array &$form_state) {
    return array();
  }

  /**
   * {@inheritdoc}
   */
  public function validateConfigurationForm(array $form, array &$form_state) {
  }

  /**
   * {@inheritdoc}
   */
  public function submitConfigurationForm(array $form, array &$form_state) {
    if (!empty($form_state['values'])) {
      $this
        ->setConfiguration($form_state['values']);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SearchApiAutocompleteSuggesterInterface::getAutocompleteSuggestions public function Retrieves autocompletion suggestions for some user input. 2
SearchApiAutocompleteSuggesterPluginBase::$configuration protected property The suggester plugin's configuration.
SearchApiAutocompleteSuggesterPluginBase::$pluginDefinition protected property The suggester plugin's definition.
SearchApiAutocompleteSuggesterPluginBase::$pluginId protected property The suggester plugin's ID.
SearchApiAutocompleteSuggesterPluginBase::$search protected property The search this suggester is attached to.
SearchApiAutocompleteSuggesterPluginBase::buildConfigurationForm public function Constructs the plugin's configuration form. Overrides SearchApiAutocompleteSuggesterInterface::buildConfigurationForm 2
SearchApiAutocompleteSuggesterPluginBase::create public static function Creates a new instance of this class. Overrides SearchApiAutocompleteSuggesterInterface::create
SearchApiAutocompleteSuggesterPluginBase::defaultConfiguration public function Retrieves the default configuration for this plugin. Overrides SearchApiAutocompleteSuggesterInterface::defaultConfiguration 2
SearchApiAutocompleteSuggesterPluginBase::getConfiguration public function Retrieves the plugin's configuration. Overrides SearchApiAutocompleteSuggesterInterface::getConfiguration
SearchApiAutocompleteSuggesterPluginBase::getDescription public function Retrieves the plugin's description. Overrides SearchApiAutocompleteSuggesterInterface::getDescription
SearchApiAutocompleteSuggesterPluginBase::getPluginDefinition public function Retrieves the plugin's definition. Overrides SearchApiAutocompleteSuggesterInterface::getPluginDefinition
SearchApiAutocompleteSuggesterPluginBase::getPluginId public function Retrieves the plugin's ID. Overrides SearchApiAutocompleteSuggesterInterface::getPluginId
SearchApiAutocompleteSuggesterPluginBase::getSearch public function Retrieves the search this plugin is configured for. Overrides SearchApiAutocompleteSuggesterInterface::getSearch
SearchApiAutocompleteSuggesterPluginBase::label public function Retrieves the plugin's label. Overrides SearchApiAutocompleteSuggesterInterface::label
SearchApiAutocompleteSuggesterPluginBase::setConfiguration public function Sets the plugin's configuration. Overrides SearchApiAutocompleteSuggesterInterface::setConfiguration
SearchApiAutocompleteSuggesterPluginBase::submitConfigurationForm public function Submits the plugin's configuration form. Overrides SearchApiAutocompleteSuggesterInterface::submitConfigurationForm 2
SearchApiAutocompleteSuggesterPluginBase::supportsIndex public static function Determines whether this plugin class supports the given index. Overrides SearchApiAutocompleteSuggesterInterface::supportsIndex 1
SearchApiAutocompleteSuggesterPluginBase::validateConfigurationForm public function Validates the plugin's configuration form. Overrides SearchApiAutocompleteSuggesterInterface::validateConfigurationForm
SearchApiAutocompleteSuggesterPluginBase::__construct public function Constructs a SearchApiAutocompleteSuggesterPluginBase.