You are here

class SearchApiStatsBlock in Search API Stats 8

Same name in this branch
  1. 8 modules/search_api_stats_block/src/Plugin/Derivative/SearchApiStatsBlock.php \Drupal\search_api_stats_block\Plugin\Derivative\SearchApiStatsBlock
  2. 8 modules/search_api_stats_block/src/Plugin/Block/SearchApiStatsBlock.php \Drupal\search_api_stats_block\Plugin\Block\SearchApiStatsBlock

Provides block plugin definitions for mymodule blocks.

Hierarchy

Expanded class hierarchy of SearchApiStatsBlock

See also

\Drupal\search_api_stats_block\Plugin\Block\SearchApiStatsBlock

File

modules/search_api_stats_block/src/Plugin/Derivative/SearchApiStatsBlock.php, line 16

Namespace

Drupal\search_api_stats_block\Plugin\Derivative
View source
class SearchApiStatsBlock extends DeriverBase implements ContainerDeriverInterface {

  /**
   * List of derivative definitions.
   *
   * @var array
   */
  protected $derivatives = [];

  /**
   * The base plugin ID this derivative is for.
   *
   * @var string
   */
  protected $basePluginId;

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {

    /** @var \Drupal\search_api\Entity\Index[] $indexes */
    $indexes = Index::loadMultiple();
    foreach ($indexes as $key => $index) {
      $this->derivatives[$key] = $base_plugin_definition;
      $this->derivatives[$key]['admin_label'] = t('Search API stats block: :label', [
        ':label' => $index
          ->label(),
      ]);
      $this->derivatives[$key]['config_dependencies']['config'] = [];
    }
    return $this->derivatives;
  }

  /**
   * Constructs an EntityDeriver object.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_manager) {
    $this->basePluginId = $base_plugin_id;
    $this->entityTypeManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($base_plugin_id, $container
      ->get('entity_type.manager'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
SearchApiStatsBlock::$basePluginId protected property The base plugin ID this derivative is for.
SearchApiStatsBlock::$derivatives protected property List of derivative definitions. Overrides DeriverBase::$derivatives
SearchApiStatsBlock::$entityTypeManager protected property The entity manager.
SearchApiStatsBlock::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
SearchApiStatsBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
SearchApiStatsBlock::__construct public function Constructs an EntityDeriver object.