FacetSourcePluginManager.php in Facets 8
File
src/FacetSource/FacetSourcePluginManager.php
View source
<?php
namespace Drupal\facets\FacetSource;
use Drupal\Component\Plugin\Exception\PluginException;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
use Drupal\facets\Annotation\FacetsFacetSource;
class FacetSourcePluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facets/facet_source', $namespaces, $module_handler, FacetSourcePluginInterface::class, FacetsFacetSource::class);
$this
->setCacheBackend($cache_backend, 'facet_source_plugins');
}
public function processDefinition(&$definition, $plugin_id) {
parent::processDefinition($definition, $plugin_id);
if (!isset($definition['id'])) {
throw new PluginException(sprintf('The facet source plugin %s must define the id property.', $plugin_id));
}
if ($definition['id'] === 'search_api' && !$this->moduleHandler
->moduleExists('search_api')) {
return;
}
foreach ([
'display_id',
'label',
] as $required_property) {
if (empty($definition[$required_property])) {
throw new PluginException(sprintf('The facet source plugin %s must define the %s property.', $plugin_id, $required_property));
}
}
}
protected function findDefinitions() {
$defs = parent::findDefinitions();
$defs = array_filter($defs, function ($item) {
if ($item['id'] === 'search_api' && !$this->moduleHandler
->moduleExists('search_api')) {
return FALSE;
}
return TRUE;
});
return $defs;
}
}