You are here

abstract class SearchPluginDeriverBase in Search API Autocomplete 8

Provides a base class for search plugin derivers.

Hierarchy

Expanded class hierarchy of SearchPluginDeriverBase

3 files declare their use of SearchPluginDeriverBase
PageDeriver.php in src/Plugin/search_api_autocomplete/search/PageDeriver.php
search_api_autocomplete.module in ./search_api_autocomplete.module
Adds autocomplete capabilities for Search API searches.
ViewsDeriver.php in src/Plugin/search_api_autocomplete/search/ViewsDeriver.php

File

src/Search/SearchPluginDeriverBase.php, line 14

Namespace

Drupal\search_api_autocomplete\Search
View source
abstract class SearchPluginDeriverBase extends DeriverBase implements ContainerDeriverInterface {
  use StringTranslationTrait;

  /**
   * Existing instances of this class.
   *
   * @var \Drupal\search_api_autocomplete\Search\SearchPluginDeriverBase[][]
   */
  protected static $instances = [];

  /**
   * {@inheritdoc}
   */
  protected $derivatives = NULL;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    $deriver = new static();
    $deriver
      ->setEntityTypeManager($container
      ->get('entity_type.manager'));
    $deriver
      ->setStringTranslation($container
      ->get('string_translation'));
    static::$instances[$base_plugin_id][] = $deriver;
    return $deriver;
  }

  /**
   * Resets the statically cached derivatives for all instances of this class.
   *
   * @param string|null $base_plugin_id
   *   (optional) If given, only reset the caches on derivers for the given base
   *   plugin ID.
   */
  public static function resetStaticDerivativeCaches($base_plugin_id = NULL) {
    $instances = static::$instances;
    if ($base_plugin_id) {
      $instances = !empty($instances[$base_plugin_id]) ? $instances[$base_plugin_id] : [];
    }
    foreach ($instances as $deriver) {
      $deriver->derivatives = NULL;
    }
  }

  /**
   * Retrieves the entity manager.
   *
   * @return \Drupal\Core\Entity\EntityTypeManagerInterface
   *   The entity manager.
   */
  public function getEntityTypeManager() {
    return $this->entityTypeManager;
  }

  /**
   * Sets the entity manager.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity manager.
   *
   * @return $this
   */
  public function setEntityTypeManager(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
    return $this;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DeriverBase::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface::getDerivativeDefinitions 39
SearchPluginDeriverBase::$derivatives protected property List of derivative definitions. Overrides DeriverBase::$derivatives
SearchPluginDeriverBase::$entityTypeManager protected property The entity manager.
SearchPluginDeriverBase::$instances protected static property Existing instances of this class.
SearchPluginDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SearchPluginDeriverBase::getEntityTypeManager public function Retrieves the entity manager.
SearchPluginDeriverBase::resetStaticDerivativeCaches public static function Resets the statically cached derivatives for all instances of this class.
SearchPluginDeriverBase::setEntityTypeManager public function Sets the entity manager.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.