SearchApiDisplayDeriver.php in Facets 8
File
src/Plugin/facets/facet_source/SearchApiDisplayDeriver.php
View source
<?php
namespace Drupal\facets\Plugin\facets\facet_source;
use Drupal\Component\Plugin\PluginBase;
use Drupal\facets\FacetSource\FacetSourceDeriverBase;
use Drupal\search_api\IndexInterface;
class SearchApiDisplayDeriver extends FacetSourceDeriverBase {
public function getDerivativeDefinitions($base_plugin_definition) {
$base_plugin_id = $base_plugin_definition['id'];
$plugin_derivatives = [];
$display_plugin_manager = $this
->getSearchApiDisplayPluginManager();
foreach ($display_plugin_manager
->getDefinitions() as $display_id => $display_definition) {
if (!isset($display_definition['index'])) {
continue;
}
$display = $display_plugin_manager
->createInstance($display_id);
$index = $display
->getIndex();
if (!$index instanceof IndexInterface) {
continue;
}
$server = $index
->getServerInstance();
if (empty($server) || !$server
->supportsFeature('search_api_facets')) {
continue;
}
$machine_name = str_replace(':', '__', $display
->getPluginId());
$plugin_derivatives[$machine_name] = [
'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
'display_id' => $display_id,
'label' => $display
->label(),
'description' => $display
->getDescription(),
] + $base_plugin_definition;
}
uasort($plugin_derivatives, [
$this,
'compareDerivatives',
]);
$this->derivatives[$base_plugin_id] = $plugin_derivatives;
return $this->derivatives[$base_plugin_id];
}
}