class SearchApiPageDeriver in Search API Pages 8
Derives a display plugin definition for all pages.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\search_api\Display\DisplayDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\search_api_page\Plugin\search_api\display\SearchApiPageDeriver
- class \Drupal\search_api\Display\DisplayDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of SearchApiPageDeriver
File
- src/
Plugin/ search_api/ display/ SearchApiPageDeriver.php, line 11
Namespace
Drupal\search_api_page\Plugin\search_api\displayView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
DisplayDeriverBase:: |
protected | property |
List of derivative definitions. Overrides DeriverBase:: |
|
DisplayDeriverBase:: |
protected | property | The entity type manager. | |
DisplayDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
DisplayDeriverBase:: |
public | function | Retrieves the entity type manager. | |
DisplayDeriverBase:: |
public | function | Sets the entity type manager. | |
SearchApiPageDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
SearchApiPageDeriver:: |
protected | function | Creates derived plugin definitions for pages. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |