JsonApiFacetsDeriver.php in JSON:API Search API 8
File
modules/jsonapi_search_api_facets/src/Plugin/facets/facet_source/JsonApiFacetsDeriver.php
View source
<?php
namespace Drupal\jsonapi_search_api_facets\Plugin\facets\facet_source;
use Drupal\Component\Plugin\PluginBase;
use Drupal\facets\FacetSource\FacetSourceDeriverBase;
class JsonApiFacetsDeriver extends FacetSourceDeriverBase {
public function getDerivativeDefinitions($base_plugin_definition) {
$derivatives = [];
foreach ($this->entityTypeManager
->getStorage('search_api_index')
->getQuery()
->execute() as $index) {
if ($this->entityTypeManager
->getStorage('search_api_index')
->load($index)
->getServerInstance()
->supportsFeature('search_api_facets')) {
$derivatives[$index] = [
'id' => $base_plugin_definition['id'] . PluginBase::DERIVATIVE_SEPARATOR . $index,
'display_id' => strtr('jsonapi_search_api_facets_!index', [
'!index' => $index,
]),
'label' => $this
->t('JSON:API Search API Facets: @index', [
'@index' => $index,
]),
'index' => $index,
] + $base_plugin_definition;
}
}
return $derivatives;
}
}