class SearchApiDisplayDeriver in Facets 8
Derives a facet source plugin definition for every Search API display plugin.
This facet source supports all search api display sources.
Hierarchy
- class \Drupal\facets\FacetSource\FacetSourceDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\facets\Plugin\facets\facet_source\SearchApiDisplayDeriver
Expanded class hierarchy of SearchApiDisplayDeriver
See also
\Drupal\facets\Plugin\facets\facet_source\SearchApi
File
- src/
Plugin/ facets/ facet_source/ SearchApiDisplayDeriver.php, line 16
Namespace
Drupal\facets\Plugin\facets\facet_sourceView source
class SearchApiDisplayDeriver extends FacetSourceDeriverBase {
/**
* {@inheritdoc}
*/
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 'index' is not set on the plugin, we can't load the index.
if (!isset($display_definition['index'])) {
continue;
}
/** @var \Drupal\search_api\Display\DisplayInterface $display */
$display = $display_plugin_manager
->createInstance($display_id);
$index = $display
->getIndex();
// If we can't reliably load the index, we should just cancel trying to
// create a derivative for this display.
if (!$index instanceof IndexInterface) {
continue;
}
// Get the server linked to the index.
$server = $index
->getServerInstance();
// If facets are not supported by the server, don't actually add this to
// the list of plugins.
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];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FacetSourceDeriverBase:: |
protected | property | List of derivative definitions. | |
FacetSourceDeriverBase:: |
protected | property | The entity manager. | |
FacetSourceDeriverBase:: |
protected | property | The search api display plugin manager. | |
FacetSourceDeriverBase:: |
public | function | Compares two plugin definitions according to their labels. | |
FacetSourceDeriverBase:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
FacetSourceDeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
FacetSourceDeriverBase:: |
public | function | Retrieves the entity manager. | |
FacetSourceDeriverBase:: |
public | function | Returns the display plugin manager. | |
FacetSourceDeriverBase:: |
public | function | Sets the entity manager. | |
FacetSourceDeriverBase:: |
public | function | Sets search api's display plugin manager. | |
SearchApiDisplayDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface:: |
|
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. |