SearchApiPageDeriver.php in Search API Pages 8
File
src/Plugin/search_api/display/SearchApiPageDeriver.php
View source
<?php
namespace Drupal\search_api_page\Plugin\search_api\display;
use Drupal\search_api\Display\DisplayDeriverBase;
use Drupal\search_api_page\Entity\SearchApiPage;
class SearchApiPageDeriver extends DisplayDeriverBase {
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;
}
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;
}
}