class CoreViewsExposedFilterDeriver in Core Views Facets 8
Derives a facet source plugin definition for views with exposed filters.
Hierarchy
- class \Drupal\facets\FacetSource\FacetSourceDeriverBase implements ContainerDeriverInterface uses StringTranslationTrait
- class \Drupal\core_views_facets\Plugin\facets\facet_source\CoreViewsExposedFilterDeriver
Expanded class hierarchy of CoreViewsExposedFilterDeriver
File
- src/
Plugin/ facets/ facet_source/ CoreViewsExposedFilterDeriver.php, line 14
Namespace
Drupal\core_views_facets\Plugin\facets\facet_sourceView source
class CoreViewsExposedFilterDeriver extends FacetSourceDeriverBase {
/**
* The base plugin ID.
*
* @var string
*/
protected $basePluginId;
/**
* The view storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface
*/
protected $viewStorage;
/**
* Constructs a FacetSource object.
*
* @param string $base_plugin_id
* The base plugin ID.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->basePluginId = $base_plugin_id;
$this
->setEntityTypeManager($entity_type_manager);
$this->viewStorage = $this->entityTypeManager
->getStorage('view');
$this
->setStringTranslation($string_translation);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
if (!isset($this->derivatives[$this->basePluginId])) {
$plugin_derivatives = [];
/** @var \Drupal\views\Entity\View[] $all_views */
$all_views = $this->viewStorage
->loadMultiple();
foreach ($all_views as $view) {
// Do not return results for disabled views.
if (!$view
->status()) {
continue;
}
$displays = $view
->get('display');
foreach ($displays as $name => $display_info) {
if ($display_info['display_plugin'] === 'page') {
$view_executable = $view
->getExecutable();
$view_executable
->setDisplay($name);
if ($view_executable && $view_executable
->getQuery() instanceof Sql) {
$exposed_filter_available = FALSE;
foreach ($view_executable
->getHandlers('filter', $name) as $filter) {
if (!empty($filter['exposed']) && $filter['exposed'] == TRUE) {
$exposed_filter_available = TRUE;
}
}
if (!$exposed_filter_available) {
continue;
}
$machine_name = $view
->id() . '__' . $name;
$plugin_derivatives[$machine_name] = [
'id' => $this->basePluginId . ':' . $machine_name,
'label' => $this
->t('Core view exposed filter: %view_name, display: %display_title', [
'%view_name' => $view
->label(),
'%display_title' => $display_info['display_title'],
]),
'description' => $this
->t('Provides a facet source.'),
'display_id' => $machine_name,
'config_dependencies' => [
'config' => [
$view
->getConfigDependencyName(),
],
],
'view_id' => $view
->id(),
'view_display' => $name,
] + $base_plugin_definition;
}
}
}
}
$this->derivatives[$this->basePluginId] = $plugin_derivatives;
}
return $this->derivatives[$this->basePluginId];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CoreViewsExposedFilterDeriver:: |
protected | property | The base plugin ID. | |
CoreViewsExposedFilterDeriver:: |
protected | property | The view storage. | |
CoreViewsExposedFilterDeriver:: |
public static | function |
Creates a new class instance. Overrides FacetSourceDeriverBase:: |
|
CoreViewsExposedFilterDeriver:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverInterface:: |
|
CoreViewsExposedFilterDeriver:: |
public | function | Constructs a FacetSource object. | |
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 | 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. | |
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. |