Skip to content
......@@ -2,18 +2,19 @@
/**
* @file
* Contains \Drupal\facetapi\FacetSource\FacetSourceDeriverBase.
* Contains \Drupal\facets\FacetSource\FacetSourceDeriverBase.
*/
namespace Drupal\facetapi\FacetSource;
namespace Drupal\facets\FacetSource;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
* A base class for facet source derivers.
*/
abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
......@@ -81,7 +82,6 @@ abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
return isset($derivatives[$derivative_id]) ? $derivatives[$derivative_id] : NULL;
}
/**
* Compares two plugin definitions according to their labels.
*
......
<?php
/**+
/**
* @file
* Contains \Drupal\facetapi\FacetSource\FacetSourcePluginBase.
* Contains \Drupal\facets\FacetSource\FacetSourcePluginBase.
*/
namespace Drupal\facetapi\FacetSource;
namespace Drupal\facets\FacetSource;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\FacetApi\FacetInterface;
use Drupal\Facets\FacetInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Defines a base class from which other facet sources may extend.
......@@ -21,31 +23,44 @@ use Drupal\FacetApi\FacetInterface;
* - label: The human-readable name of the datasource, translated.
* - description: A human-readable description for the datasource, translated.
*
* @see \Drupal\facetapi\Annotation\FacetApiFacetSource
* @see \Drupal\facetapi\FacetSource\FacetSourcePluginManager
* @see \Drupal\facetapi\FacetSource\FacetSourceInterface
* @see \Drupal\facets\Annotation\FacetsFacetSource
* @see \Drupal\facets\FacetSource\FacetSourcePluginManager
* @see \Drupal\facets\FacetSource\FacetSourcePluginInterface
* @see plugin_api
*/
abstract class FacetSourcePluginBase extends PluginBase implements FacetSourceInterface, ContainerFactoryPluginInterface {
abstract class FacetSourcePluginBase extends PluginBase implements FacetSourcePluginInterface, ContainerFactoryPluginInterface {
/**
* The plugin manager.
*
* @var \Drupal\facetapi\QueryType\QueryTypePluginManager
* @var \Drupal\facets\QueryType\QueryTypePluginManager
*/
protected $queryTypePluginManager;
/**
* The search keys, or query text, submitted by the user.
*
* @var string
*/
protected $keys;
/**
* The facet we're editing for.
*
* @var \Drupal\facets\FacetInterface
*/
protected $facet;
/**
* {@inheritdoc}
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
$query_type_plugin_manager
) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, $query_type_plugin_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->queryTypePluginManager = $query_type_plugin_manager;
if (isset($configuration['facet'])) {
$this->facet = $configuration['facet'];
}
}
/**
......@@ -53,8 +68,8 @@ abstract class FacetSourcePluginBase extends PluginBase implements FacetSourceIn
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
// Insert the plugin manager for query types.
/** @var \Drupal\facetapi\QueryType\QueryTypePluginManager $query_type_plugin_manager */
$query_type_plugin_manager = $container->get('plugin.manager.facetapi.query_type');
/** @var \Drupal\facets\QueryType\QueryTypePluginManager $query_type_plugin_manager */
$query_type_plugin_manager = $container->get('plugin.manager.facets.query_type');
return new static($configuration, $plugin_id, $plugin_definition, $query_type_plugin_manager);
}
......@@ -79,4 +94,36 @@ abstract class FacetSourcePluginBase extends PluginBase implements FacetSourceIn
public function isRenderedInCurrentRequest() {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function setSearchKeys($keys) {
$this->keys = $keys;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSearchKeys() {
return $this->keys;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
return TRUE;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$facet_source_id = $this->facet->getFacetSourceId();
$field_identifier = $form_state->getValue('facet_source_configs')[$facet_source_id]['field_identifier'];
$this->facet->setFieldIdentifier($field_identifier);
}
}
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facetapi\FacetSource\FacetSourcePluginManager.
* Contains \Drupal\facets\FacetSource\FacetSourcePluginManager.
*/
namespace Drupal\facetapi\FacetSource;
namespace Drupal\facets\FacetSource;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
......@@ -14,25 +14,17 @@ use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Manages facet source plugins.
*
* @see \Drupal\facetapi\Annotation\FacetApiFacetSource
* @see \Drupal\facetapi\FacetSource\FacetSourcePluginBase
* @see \Drupal\facets\Annotation\FacetsFacetSource
* @see \Drupal\facets\FacetSource\FacetSourcePluginBase
* @see plugin_api
*/
class FacetSourcePluginManager extends DefaultPluginManager {
/**
* Constructs a FacetSourcePluginManager object.
*
* @param \Traversable $namespaces
* An object that implements \Traversable which contains the root paths
* keyed by the corresponding namespace to look for plugin implementations.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* {@inheritdoc}
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facetapi/facet_source', $namespaces, $module_handler, 'Drupal\facetapi\FacetSource\FacetSourceInterface', 'Drupal\facetapi\Annotation\FacetApiFacetSource');
parent::__construct('Plugin/facets/facet_source', $namespaces, $module_handler, 'Drupal\facets\FacetSource\FacetSourcePluginInterface', 'Drupal\facets\Annotation\FacetsFacetSource');
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\facetapi\Plugin\facetapi\empty_behavior\EmptyBehaviorNone.
*/
namespace Drupal\facetapi\Plugin\facetapi\empty_behavior;
use Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginBase;
/**
* @FacetApiEmptyBehavior(
* id = "none",
* label = @Translation("Do not display facet"),
* description = @Translation("Do not display a facet when no results"),
* )
*/
class EmptyBehaviorNone extends EmptyBehaviorPluginBase {}
This diff is collapsed.
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facetapi\Plugin\facet_api\facet_source\SearchApiViewsPage.
* Contains \Drupal\facets\Plugin\facets\facet_source\SearchApiViewsPage.
*/
namespace Drupal\facetapi\Plugin\facetapi\facet_source;
namespace Drupal\facets\Plugin\facets\facet_source;
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
use Drupal\search_api\Plugin\views\query\SearchApiQuery;
......@@ -16,9 +16,9 @@ use Drupal\views\Views;
/**
* Represents a facet source which represents the search api views.
*
* @FacetApiFacetSource(
* @FacetsFacetSource(
* id = "search_api_views",
* deriver = "Drupal\facetapi\Plugin\facetapi\facet_source\SearchApiViewsPageDeriver"
* deriver = "Drupal\facets\Plugin\facets\facet_source\SearchApiViewsPageDeriver"
* )
*/
class SearchApiViewsPage extends SearchApiBaseFacetSource {
......@@ -75,9 +75,7 @@ class SearchApiViewsPage extends SearchApiBaseFacetSource {
public function getPath() {
$view = Views::getView($this->pluginDefinition['view_id']);
$view->setDisplay($this->pluginDefinition['view_display']);
$view->execute();
return $view->getDisplay()->getOption('path');
return $view->getDisplay()->getPath();
}
/**
......