You are here

class SearchApiPageDeriver in Search API Pages 8

Derives a display plugin definition for all pages.

Hierarchy

Expanded class hierarchy of SearchApiPageDeriver

File

src/Plugin/search_api/display/SearchApiPageDeriver.php, line 11

Namespace

Drupal\search_api_page\Plugin\search_api\display
View source
class SearchApiPageDeriver extends DisplayDeriverBase {

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    if (isset($this->derivatives)) {
      return $this->derivatives;
    }
    $this->derivatives = [];
    $pages = SearchApiPage::loadMultiple();
    if (empty($pages)) {
      return $this->derivatives;
    }
    $this->derivatives = $this
      ->getDerivatives($pages, $base_plugin_definition);
    return $this->derivatives;
  }

  /**
   * Creates derived plugin definitions for pages.
   *
   * @param \Drupal\search_api_page\SearchApiPageInterface[] $pages
   *   The pages to create plugins for.
   * @param array $base_plugin_definition
   *   The plugin definition for this plugin.
   *
   * @return array
   *   Returns an array of plugin definitions, keyed by derivative ID.
   */
  protected function getDerivatives(array $pages, array $base_plugin_definition) {
    $plugin_derivatives = [];
    foreach ($pages as $page) {
      $label = $page
        ->label();
      $description = $this
        ->t('The %label search page.', [
        '%label' => $label,
      ]);
      $plugin_derivatives[$page
        ->id()] = [
        'label' => $label,
        'description' => $description,
        'index' => $page
          ->getIndex(),
        'path' => '/' . $page
          ->getPath(),
      ] + $base_plugin_definition;
    }
    return $plugin_derivatives;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DisplayDeriverBase::$derivatives protected property List of derivative definitions. Overrides DeriverBase::$derivatives
DisplayDeriverBase::$entityTypeManager protected property The entity type manager.
DisplayDeriverBase::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DisplayDeriverBase::getEntityTypeManager public function Retrieves the entity type manager.
DisplayDeriverBase::setEntityTypeManager public function Sets the entity type manager.
SearchApiPageDeriver::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
SearchApiPageDeriver::getDerivatives protected function Creates derived plugin definitions for pages.
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.