diff --git a/core_search_facets/src/FacetsQuery.php b/core_search_facets/src/FacetsQuery.php
index 857c861aed8a8d2176d585e1ee69061a8e4a567d..32f5e9a16a30942b09b74ca2514bfbc927cf0c77 100644
--- a/core_search_facets/src/FacetsQuery.php
+++ b/core_search_facets/src/FacetsQuery.php
@@ -24,11 +24,8 @@ class FacetsQuery extends SearchQuery {
*
* @param array $query_info
* An associative array of query information.
- * @param $table_alias
+ * @param string $table_alias
* The alias of the table being joined.
- *
- * @return FacetsQuery
- * An instance of this class.
*/
public function addFacetJoin(array $query_info, $table_alias) {
if (isset($query_info['joins'][$table_alias])) {
@@ -46,7 +43,7 @@ class FacetsQuery extends SearchQuery {
* @param array $query_info
* An associative array of query information.
*
- * @return FacetsQuery
+ * @return FacetsQuery
* An instance of this class.
*/
public function addFacetField(array $query_info) {
@@ -120,5 +117,5 @@ class FacetsQuery extends SearchQuery {
public function getSearchExpression() {
return $this->searchExpression;
}
-}
+}
diff --git a/core_search_facets/src/Plugin/CoreSearchFacetSourceInterface.php b/core_search_facets/src/Plugin/CoreSearchFacetSourceInterface.php
index 58e22e3461d100d3dbc23c87eec1e7e9d4b4c37a..fa16be56bce0f1b038396ca0094c0ec387e4d885 100644
--- a/core_search_facets/src/Plugin/CoreSearchFacetSourceInterface.php
+++ b/core_search_facets/src/Plugin/CoreSearchFacetSourceInterface.php
@@ -10,12 +10,11 @@ namespace Drupal\core_search_facets\Plugin;
use Drupal\facets\FacetInterface;
/**
- *
+ * Additional interface for core facet sources.
*
* A facet source is used to abstract the data source where facets can be added
* to. A good example of this is a search api view. There are other possible
* facet data sources, these all implement the FacetSourceInterface.
- *
*/
interface CoreSearchFacetSourceInterface {
@@ -23,6 +22,7 @@ interface CoreSearchFacetSourceInterface {
* Sets the facet query object.
*
* @return \Drupal\core_search_facets\FacetsQuery
+ * The facet query object.
*/
public function getFacetQueryExtender();
@@ -47,4 +47,3 @@ interface CoreSearchFacetSourceInterface {
public function getQueryInfo(FacetInterface $facet);
}
-
diff --git a/core_search_facets/src/Plugin/Search/NodeSearchFacets.php b/core_search_facets/src/Plugin/Search/NodeSearchFacets.php
index f93ab04be8396f7e5183eb30f98c54af37f8728a..ab5687c659fa347dd12a609795b06dd636085075 100644
--- a/core_search_facets/src/Plugin/Search/NodeSearchFacets.php
+++ b/core_search_facets/src/Plugin/Search/NodeSearchFacets.php
@@ -39,9 +39,9 @@ class NodeSearchFacets extends NodeSearch {
Config $search_settings,
LanguageManagerInterface $language_manager,
RendererInterface $renderer,
- AccountInterface $account = NULL,
$facet_source_plugin_manager,
- $request_stack) {
+ $request_stack,
+ AccountInterface $account = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $database, $entity_manager, $module_handler, $search_settings, $language_manager, $renderer, $account);
/** @var \Symfony\Component\HttpFoundation\RequestStack $request_stack */
@@ -65,9 +65,9 @@ class NodeSearchFacets extends NodeSearch {
$container->get('config.factory')->get('search.settings'),
$container->get('language_manager'),
$container->get('renderer'),
- $container->get('current_user'),
$container->get('plugin.manager.facets.facet_source'),
- $container->get('request_stack')
+ $container->get('request_stack'),
+ $container->get('current_user')
);
}
@@ -80,7 +80,7 @@ class NodeSearchFacets extends NodeSearch {
$used_advanced = !empty($parameters[self::ADVANCED_FORM]);
if ($used_advanced) {
$f = isset($parameters['f']) ? (array) $parameters['f'] : array();
- $defaults = $this->parseAdvancedDefaults($f, $keys);
+ $defaults = $this->parseAdvancedDefaults($f, $keys);
}
else {
$defaults = array('keys' => $keys);
@@ -188,4 +188,3 @@ class NodeSearchFacets extends NodeSearch {
}
}
-
diff --git a/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php b/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
index d10dd0b7e59af050dd20c3294eebae1fc1f169f8..2beb11dd2b158519a079890e55a8d071ed4c6a45 100644
--- a/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
+++ b/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php
@@ -2,7 +2,7 @@
/**
* @file
- * Contains \Drupal\core_search_facets\Plugin\facets\facet_source\CoreNodeSearchFacetSource
+ * Contains \Drupal\core_search_facets\Plugin\facets\facet_source\CoreNodeSearchFacetSource.
*/
namespace Drupal\core_search_facets\Plugin\facets\facet_source;
@@ -95,7 +95,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
$view->execute();
return $view->getDisplay()->getOption('path');*/
- return;
+ return '';
}
/**
@@ -126,8 +126,13 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
}
/**
- * @param $field_id
+ * Get the query types for a data type.
+ *
+ * @param string $field_id
+ * The field id.
+ *
* @return array
+ * An array of query types.
*/
public function getQueryTypesForDataType($field_id) {
$query_types = [];
@@ -194,19 +199,20 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* {@inheritdoc}
*/
public function getFacetQueryExtender() {
- //if (!$this->facetQueryExtender) {
-
- //$this->facetQueryExtender = db_select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\search\ViewsSearchQuery');
- //$this->searchQuery->searchExpression($input, $this->searchType);
- //$this->searchQuery->publicParseSearchExpression();
-
+ // If (!$this->facetQueryExtender) {
+ // $this->facetQueryExtender = db_select('search_index',
+ // 'i',
+ // array('target' => 'replica'))
+ // ->extend('Drupal\search\ViewsSearchQuery');
+ // $this->searchQuery->searchExpression($input, $this->searchType);
+ // $this->searchQuery->publicParseSearchExpression();
$this->facetQueryExtender = db_select('search_index', 'i', array('target' => 'replica'))->extend('Drupal\core_search_facets\FacetsQuery');
$this->facetQueryExtender->join('node_field_data', 'n', 'n.nid = i.sid');
$this->facetQueryExtender
- //->condition('n.status', 1)
+ // ->condition('n.status', 1).
->addTag('node_access')
->searchExpression($this->keys, 'node_search');
- //}
+ // }.
return $this->facetQueryExtender;
}
@@ -214,45 +220,45 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* {@inheritdoc}
*/
public function getQueryInfo(FacetInterface $facet) {
- //if (!$facet['field api name']) {
+ // If (!$facet['field api name']) {
// We add the language code of the indexed item to the result of the query.
// So in this case we need to use the search_index table alias (i) for the
// langcode field. Otherwise we will have same nid for multiple languages
// as result. For more details see NodeSearch::findResults().
- $table_alias = $facet->getFieldIdentifier() == 'langcode' ? 'i' : 'n';
- $query_info = [
- 'fields' => [
- $table_alias . '.' . $facet->getFieldIdentifier() => [
- 'table_alias' => $table_alias,
- 'field' => $facet->getFieldIdentifier(),
- ],
+ $table_alias = $facet->getFieldIdentifier() == 'langcode' ? 'i' : 'n';
+ $query_info = [
+ 'fields' => [
+ $table_alias . '.' . $facet->getFieldIdentifier() => [
+ 'table_alias' => $table_alias,
+ 'field' => $facet->getFieldIdentifier(),
],
- ];
- //}
+ ],
+ ];
+ // }
/*else {
- $query_info = array();
-
- // Gets field info, finds table name and field name.
- $field = field_info_field($facet['field api name']);
- $table = _field_sql_storage_tablename($field);
-
- // Iterates over columns, adds fields to query info.
- foreach ($field['columns'] as $column_name => $attributes) {
- $column = _field_sql_storage_columnname($field['field_name'], $column_name);
- $query_info['fields'][$table . '.' . $column] = array(
- 'table_alias' => $table,
- 'field' => $column,
- );
- }
+ $query_info = array();
+
+ // Gets field info, finds table name and field name.
+ $field = field_info_field($facet['field api name']);
+ $table = _field_sql_storage_tablename($field);
+
+ // Iterates over columns, adds fields to query info.
+ foreach ($field['columns'] as $column_name => $attributes) {
+ $column = _field_sql_storage_columnname($field['field_name'], $column_name);
+ $query_info['fields'][$table . '.' . $column] = array(
+ 'table_alias' => $table,
+ 'field' => $column,
+ );
+ }
- // Adds the join on the node table.
- $query_info['joins'] = array(
- $table => array(
- 'table' => $table,
- 'alias' => $table,
- 'condition' => "n.vid = $table.revision_id",
- ),
- );
+ // Adds the join on the node table.
+ $query_info['joins'] = array(
+ $table => array(
+ 'table' => $table,
+ 'alias' => $table,
+ 'condition' => "n.vid = $table.revision_id",
+ ),
+ );
}*/
// Returns query info, makes sure all keys are present.
@@ -263,12 +269,14 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
}
/**
+ * Checks if the search has facets.
+ *
* @TODO move to the Base class???
*/
public function hasFacets() {
$manager = \Drupal::service('entity_type.manager')->getStorage('facets_facet');
$facets = $manager->loadMultiple();
- foreach($facets as $facet) {
+ foreach ($facets as $facet) {
if ($facet->getFacetSourceId() == $this->getPluginId()) {
return TRUE;
}
diff --git a/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSourceDeriver.php b/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSourceDeriver.php
index 5b1c134086a8c5bc3c49a0438f4b4d021f6923c1..f1ba3cdfba6679f16102d87bd081b3300ba2dd06 100644
--- a/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSourceDeriver.php
+++ b/core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSourceDeriver.php
@@ -20,6 +20,9 @@ class CoreNodeSearchFacetSourceDeriver extends FacetSourceDeriverBase {
protected $searchManager;
+ /**
+ * Create an instance of the deriver.
+ */
public function __construct(ContainerInterface $container, $base_plugin_id, $search_manager, $entity_type_manager) {
$this->searchManager = $search_manager;
$this->entityTypeManager = $entity_type_manager;
@@ -48,15 +51,15 @@ class CoreNodeSearchFacetSourceDeriver extends FacetSourceDeriverBase {
$pages = $this->entityTypeManager->getStorage('search_page')->loadMultiple();
- foreach($pages as $machine_name => $page) {
- /** @var \Drupal\search\Entity\SearchPage $page * */
+ foreach ($pages as $machine_name => $page) {
+ /* @var \Drupal\search\Entity\SearchPage $page * */
if ($page->get('plugin') == 'node_search') {
// Detect if the plugin has "faceted" definition.
$plugin_derivatives[$machine_name] = [
- 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
- 'label' => $this->t('Core Search Page: %page_name', ['%page_name' => $page->get('label')]),
- 'description' => $this->t('Provides a facet source.'),
- ] + $base_plugin_definition;
+ 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
+ 'label' => $this->t('Core Search Page: %page_name', ['%page_name' => $page->get('label')]),
+ 'description' => $this->t('Provides a facet source.'),
+ ] + $base_plugin_definition;
}
uasort($plugin_derivatives, array($this, 'compareDerivatives'));
diff --git a/core_search_facets/src/Plugin/facets/query_type/CoreNodeSearchString.php b/core_search_facets/src/Plugin/facets/query_type/CoreNodeSearchString.php
index 228d2409fab5a0a489844c1631d3f55b0a96aa01..3cdc1c0521206dd0331570cefd464f67958689f9 100644
--- a/core_search_facets/src/Plugin/facets/query_type/CoreNodeSearchString.php
+++ b/core_search_facets/src/Plugin/facets/query_type/CoreNodeSearchString.php
@@ -11,6 +11,7 @@ use Drupal\facets\QueryType\QueryTypePluginBase;
use Drupal\facets\Result\Result;
/**
+ * A string query type for core.
*
* @FacetsQueryType(
* id = "core_node_search_string",
@@ -31,11 +32,11 @@ class CoreNodeSearchString extends QueryTypePluginBase {
*/
public function execute() {
- /** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facetSource */
- $facetSource = $this->facet->getFacetSource();
- $query_info = $facetSource->getQueryInfo($this->facet);
+ /** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facet_source */
+ $facet_source = $this->facet->getFacetSource();
+ $query_info = $facet_source->getQueryInfo($this->facet);
/** @var \Drupal\core_search_facets\FacetsQuery $facet_query */
- $facet_query = $facetSource->getFacetQueryExtender();
+ $facet_query = $facet_source->getFacetQueryExtender();
$tables_joined = [];
// Add the filter to the query if there are active values.
@@ -49,11 +50,12 @@ class CoreNodeSearchString extends QueryTypePluginBase {
// Adds adds join to search query, makes sure it is only added once.
if (isset($query_info['joins'][$field_info['table_alias']])) {
- if (!isset($tables_joined[$field_info['table_alias']])) {
- $tables_joined[$field_info['table_alias']] = TRUE;
- $join_info = $query_info['joins'][$field_info['table_alias']];
- $this->query->join($join_info['table'], $join_info['alias'], $join_info['condition']);
- }
+ if (!isset($tables_joined[$field_info['table_alias']])) {
+ $tables_joined[$field_info['table_alias']] = TRUE;
+ $join_info = $query_info['joins'][$field_info['table_alias']];
+ $this->query->join($join_info['table'], $join_info['alias'],
+ $join_info['condition']);
+ }
}*/
// Adds facet conditions to the queries.
@@ -68,12 +70,12 @@ class CoreNodeSearchString extends QueryTypePluginBase {
* {@inheritdoc}
*/
public function build() {
- /** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facetSource */
- $facetSource = $this->facet->getFacetSource();
- $query_info = $facetSource->getQueryInfo($this->facet);
+ /* @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facet_source */
+ $facet_source = $this->facet->getFacetSource();
+ $query_info = $facet_source->getQueryInfo($this->facet);
/** @var \Drupal\core_search_facets\FacetsQuery $facet_query */
- $facet_query = $facetSource->getFacetQueryExtender();
+ $facet_query = $facet_source->getFacetQueryExtender();
$facet_query->addFacetField($query_info);
@@ -94,4 +96,3 @@ class CoreNodeSearchString extends QueryTypePluginBase {
}
}
-
diff --git a/css/facets.admin.css b/css/facets.admin.css
index 503b032d8b2ed768b6d53aa3b3b3d04a75896cda..42ae2860d3f4d720b090d7174d508a7b02e2fcdf 100644
--- a/css/facets.admin.css
+++ b/css/facets.admin.css
@@ -41,4 +41,4 @@
.facets-processor-settings-facet {
margin-left: 20px;
margin-bottom: 20px;
-}
\ No newline at end of file
+}
diff --git a/src/ContextProvider/FacetContextProvider.php b/src/ContextProvider/FacetContextProvider.php
index 201906d050f83b7b5af80d3f52a257e217f50768..c663e5c0d758174050dad98e3a731d68344a2301 100644
--- a/src/ContextProvider/FacetContextProvider.php
+++ b/src/ContextProvider/FacetContextProvider.php
@@ -26,9 +26,10 @@ class FacetContextProvider implements ContextProviderInterface {
protected $facetStorage;
/**
- * Create a new instance of the context provider.
+ * Creates a new instance of the context provider.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+ * The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->facetStorage = $entity_type_manager->getStorage('facets_facet');
diff --git a/src/Controller/FacetController.php b/src/Controller/FacetController.php
index b1c0abf827204e71cfe223fd50a6f123f3b38d12..de6bb56096b7caf387562039b863315cfcac552a 100644
--- a/src/Controller/FacetController.php
+++ b/src/Controller/FacetController.php
@@ -51,7 +51,7 @@ class FacetController extends ControllerBase {
* Returns a form to edit a facet on a search api index.
*
* @param \Drupal\facets\FacetInterface $facets_facet
- * Facet currently being edited
+ * Facet currently being edited.
*
* @return array
* The facet edit form.
@@ -64,7 +64,7 @@ class FacetController extends ControllerBase {
/**
* Returns the page title for an facets's "View" tab.
*
- * @param \Drupal\facets/FacetInterface $facet
+ * @param \Drupal\facets\FacetInterface $facet
* The facet that is displayed.
*
* @return string
diff --git a/src/Entity/Facet.php b/src/Entity/Facet.php
index 5c74a7d0b1d495584420df735ccf176f8a700e72..3802c9676df4dbc8111a5ed2dc6e6eb9fc9a0b33 100644
--- a/src/Entity/Facet.php
+++ b/src/Entity/Facet.php
@@ -131,7 +131,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
/**
* The facet source belonging to this facet.
*
- * @var \Drupal\facets\FacetSourceInterface
+ * @var \Drupal\facets\FacetSource\FacetSourceInterface
*
* @see getFacetSource()
*/
@@ -170,6 +170,8 @@ class Facet extends ConfigEntityBase implements FacetInterface {
protected $processors;
/**
+ * Is the facet only visible when the facet source is only visible.
+ *
* A boolean that defines whether or not the facet is only visible when the
* facet source is visible.
*
@@ -192,12 +194,15 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
+ * Gets the widget plugin manager.
+ *
* @return \Drupal\facets\Widget\WidgetPluginManager
+ * The widget plugin manager.
*/
public function getWidgetManager() {
$container = \Drupal::getContainer();
- return $this->widget_plugin_manager ? : $container->get('plugin.manager.facets.widget');
+ return $this->widget_plugin_manager ?: $container->get('plugin.manager.facets.widget');
}
/**
@@ -245,9 +250,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
- * Get the field alias used to identify the facet in the url.
- *
- * @return mixed
+ * {@inheritdoc}
*/
public function getFieldAlias() {
// For now, create the field alias based on the field identifier.
@@ -256,9 +259,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
- * Sets an item with value to active.
- *
- * @param $value
+ * {@inheritdoc}
*/
public function setActiveItem($value) {
if (!in_array($value, $this->active_values)) {
@@ -267,9 +268,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
- * Get all the active items in the facet.
- *
- * @return mixed
+ * {@inheritdoc}
*/
public function getActiveItems() {
return $this->active_values;
@@ -356,7 +355,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
public function getFacetSource() {
if (!$this->facet_source_instance && $this->facet_source_id) {
- /** @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
+ /* @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
$facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
$this->facet_source_instance = $facet_source_plugin_manager->createInstance($this->facet_source_id);
}
@@ -379,7 +378,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
*/
protected function loadProcessors() {
if (!isset($this->processors)) {
- /** @var $processor_plugin_manager \Drupal\facets\Processor\ProcessorPluginManager */
+ /* @var $processor_plugin_manager \Drupal\facets\Processor\ProcessorPluginManager */
$processor_plugin_manager = \Drupal::service('plugin.manager.facets.processor');
$processor_settings = $this->getOption('processors', []);
@@ -389,7 +388,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
$settings = empty($processor_settings[$name]['settings']) ? [] : $processor_settings[$name]['settings'];
$settings['facet'] = $this;
- /** @var $processor \Drupal\facets\Processor\ProcessorInterface */
+ /* @var $processor \Drupal\facets\Processor\ProcessorInterface */
$processor = $processor_plugin_manager->createInstance($name, $settings);
$this->processors[$name] = $processor;
}
@@ -418,10 +417,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
- * Set an array of Result objects.
- *
- * @param array $results
- * Array containing \Drupal\facets\Result\Result objects.
+ * {@inheritdoc}
*/
public function setResults(array $results) {
$this->results = $results;
@@ -437,16 +433,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
- * Until facets supports more than just search api, this is enough.
- *
- * @return string
- */
- public function getManagerPluginId() {
- return 'facets_default';
- }
-
- /**
- * @inheritdoc
+ * {@inheritdoc}
*/
public function isActiveValue($value) {
$is_active = FALSE;
@@ -463,7 +450,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
if (!isset($this->facetSourcePlugins)) {
$this->facetSourcePlugins = [];
- /** @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
+ /* @var $facet_source_plugin_manager \Drupal\facets\FacetSource\FacetSourcePluginManager */
$facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
foreach ($facet_source_plugin_manager->getDefinitions() as $name => $facet_source_definition) {
@@ -471,7 +458,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
// Create our settings for this facet source..
$config = isset($this->facetSourcePlugins[$name]) ? $this->facetSourcePlugins[$name] : [];
- /** @var $facet_source \Drupal\facets\FacetSource\FacetSourceInterface */
+ /* @var $facet_source \Drupal\facets\FacetSource\FacetSourceInterface */
$facet_source = $facet_source_plugin_manager->createInstance($name, $config);
$this->facetSourcePlugins[$name] = $facet_source;
}
diff --git a/src/FacetInterface.php b/src/FacetInterface.php
index d50426d94e943d1c37212a298cbe5fe6d60c2417..7e39f2ae90c536438bf9f70af836a6fac6d028b5 100644
--- a/src/FacetInterface.php
+++ b/src/FacetInterface.php
@@ -7,8 +7,9 @@
namespace Drupal\facets;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
+
/**
- *
+ * The facet entity.
*/
interface FacetInterface extends ConfigEntityInterface {
@@ -16,8 +17,10 @@ interface FacetInterface extends ConfigEntityInterface {
* Sets the facet's widget plugin id.
*
* @param string $widget
+ * The widget plugin id.
*
* @return $this
+ * Returns self
*/
public function setWidget($widget);
@@ -25,6 +28,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns the facet's widget plugin id.
*
* @return string
+ * The widget plugin id.
*/
public function getWidget();
@@ -32,20 +36,26 @@ interface FacetInterface extends ConfigEntityInterface {
* Get field identifier.
*
* @return string
+ * The field identifier of this facet.
*/
public function getFieldIdentifier();
/**
* Set field identifier.
*
- * @return mixed
+ * @param string $field_identifier
+ * The field identifier of this facet.
+ *
+ * @return $this
+ * Returns self.
*/
public function setFieldIdentifier($field_identifier);
/**
* Get the field alias used to identify the facet in the url.
*
- * @return mixed
+ * @return string
+ * The field alias for the facet.
*/
public function getFieldAlias();
@@ -54,13 +64,16 @@ interface FacetInterface extends ConfigEntityInterface {
*
* @TODO: Check if fieldIdentifier can be used as well!
*
- * @return mixed
+ * @return string
+ * The name of the facet.
*/
public function getName();
+
/**
* Sets an item with value to active.
*
- * @param $value
+ * @param string $value
+ * An item that is active.
*/
public function setActiveItem($value);
@@ -68,15 +81,18 @@ interface FacetInterface extends ConfigEntityInterface {
* Get all the active items in the facet.
*
* @return mixed
+ * An array containing all active items.
*/
public function getActiveItems();
/**
- * Check if a value is active.
+ * Checks if a value is active.
*
* @param string $value
+ * The value to be checked.
*
* @return bool
+ * Is an active value.
*/
public function isActiveValue($value);
@@ -84,13 +100,15 @@ interface FacetInterface extends ConfigEntityInterface {
* Get the result for the facet.
*
* @return \Drupal\facets\Result\ResultInterface[] $results
+ * The results of the facet.
*/
public function getResults();
/**
- * Sets the reuslts for the facet.
+ * Sets the results for the facet.
*
* @param \Drupal\facets\Result\ResultInterface[] $results
+ * The results of the facet.
*/
public function setResults(array $results);
@@ -99,13 +117,15 @@ interface FacetInterface extends ConfigEntityInterface {
* Get the query type instance.
*
* @return string
+ * The query type plugin being used.
*/
public function getQueryType();
/**
* Get the plugin name for the url processor.
*
- * @return mixed
+ * @return string
+ * The id of the url processor.
*/
public function getUrlProcessorName();
@@ -141,6 +161,7 @@ interface FacetInterface extends ConfigEntityInterface {
* The new option.
*
* @return $this
+ * Returns self.
*/
public function setOption($name, $option);
@@ -151,25 +172,20 @@ interface FacetInterface extends ConfigEntityInterface {
* The new index options.
*
* @return $this
+ * Returns self.
*/
public function setOptions(array $options);
-
- /**
- * Gets the facet manager plugin id.
- *
- * @return string
- */
- public function getManagerPluginId();
-
/**
* Sets a string representation of the Facet source plugin.
*
* This is usually the name of the Search-api view.
*
* @param string $facet_source_id
+ * The facet source id.
*
* @return $this
+ * Returns self.
*/
public function setFacetSourceId($facet_source_id);
@@ -177,6 +193,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns the Facet source id.
*
* @return string
+ * The id of the facet source.
*/
public function getFacetSourceId();
@@ -192,8 +209,10 @@ interface FacetInterface extends ConfigEntityInterface {
* Load the facet sources for this facet.
*
* @param bool|TRUE $only_enabled
+ * Only return enabled facet sources.
*
* @return \Drupal\facets\FacetSource\FacetSourceInterface[]
+ * An array of facet sources.
*/
public function getFacetSources($only_enabled = TRUE);
@@ -201,8 +220,10 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns an array of processors with their configuration.
*
* @param bool|TRUE $only_enabled
+ * Only return enabled processors.
*
* @return \Drupal\facets\Processor\ProcessorInterface[]
+ * An array of processors.
*/
public function getProcessors($only_enabled = TRUE);
@@ -231,13 +252,15 @@ interface FacetInterface extends ConfigEntityInterface {
* does not show the facet source.
*
* @return $this
+ * Returns self.
*/
public function setOnlyVisibleWhenFacetSourceIsVisible($only_visible_when_facet_source_is_visible);
/**
* Returns the "only visible when facet source is visible" boolean flag.
*
- * @return boolean
+ * @return bool
+ * True when the facet is only shown on a page with the facet source.
*/
public function getOnlyVisibleWhenFacetSourceIsVisible();
diff --git a/src/FacetListBuilder.php b/src/FacetListBuilder.php
index 2bb0ca4f954961b93ec8f0834ce4e0d1c07af639..3469a797540e4f22d5d222953de121eedc263cb2 100644
--- a/src/FacetListBuilder.php
+++ b/src/FacetListBuilder.php
@@ -10,7 +10,6 @@ namespace Drupal\facets;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
-use Drupal\facets\FacetSource\FacetSourceInterface;
/**
* Builds a listing of facet entities.
@@ -102,10 +101,10 @@ class FacetListBuilder extends ConfigEntityListBuilder {
),
'title' => array(
'data' => array(
- '#type' => 'link',
- '#title' => $entity->getName(),
- '#suffix' => '
' . $entity->getFieldAlias() . ' - ' . $entity->getWidget() . '
',
- ) + $entity->urlInfo('edit-form')->toRenderArray(),
+ '#type' => 'link',
+ '#title' => $entity->getName(),
+ '#suffix' => '' . $entity->getFieldAlias() . ' - ' . $entity->getWidget() . '
',
+ ) + $entity->urlInfo('edit-form')->toRenderArray(),
'class' => array('search-api-title'),
),
'status' => array(
@@ -155,7 +154,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'You currently have no facet sources defined. You should start by adding a facet source before creating facets.
An example of a facet source is a view based on Search API or a Search API page.
Other modules can also implement a facet source by providing a plugin that implements the FacetSourceInterface.'
- )
+ ),
];
}
@@ -171,7 +170,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'#attributes' => array(
'class' => array(
'facets-groups-list',
- )
+ ),
),
);
@@ -218,7 +217,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
foreach ($facet_sources as $facet_source) {
$facet_source_groups[$facet_source['id']] = [
'facet_source' => $facet_source,
- 'facets' => []
+ 'facets' => [],
];
foreach ($facets as $facet) {
diff --git a/src/FacetManager/DefaultFacetManager.php b/src/FacetManager/DefaultFacetManager.php
index a0910011dfc952192619ff90d0e5a3ecc3d3ffc0..254ee04047b338a4d23d98cd7fd63ebbcb0121f9 100644
--- a/src/FacetManager/DefaultFacetManager.php
+++ b/src/FacetManager/DefaultFacetManager.php
@@ -33,22 +33,25 @@ class DefaultFacetManager {
/**
* The query type plugin manager.
+ *
+ * @var \Drupal\facets\QueryType\QueryTypePluginManager
+ * The query type plugin manager.
*/
- protected $query_type_plugin_manager;
+ protected $queryTypePluginManager;
/**
* The facet source plugin manager.
*
- * @var FacetSourcePluginManager
+ * @var \Drupal\facets\FacetSource\FacetSourcePluginManager
*/
- protected $facet_source_manager;
+ protected $facetSourcePluginManager;
/**
* The processor plugin manager.
*
* @var \Drupal\facets\Processor\ProcessorPluginManager
*/
- protected $processor_plugin_manager;
+ protected $processorPluginManager;
/**
* An array of facets that are being rendered.
@@ -92,35 +95,41 @@ class DefaultFacetManager {
* The id of the facet source.
*
* @var string
+ *
* @see \Drupal\facets\FacetSource\FacetSourceInterface
*/
- protected $facetsource_id;
+ protected $facetSourceId;
/**
* Set the search id.
*
- * @param string
+ * @param string $facet_source_id
* The id of the facet source.
*/
- public function setFacetSourceId($facetsource_id) {
- $this->facetsource_id = $facetsource_id;
+ public function setFacetSourceId($facet_source_id) {
+ $this->facetSourceId = $facet_source_id;
}
/**
* Constructs a new instance of the DefaultFacetManager.
*
* @param \Drupal\facets\QueryType\QueryTypePluginManager $query_type_plugin_manager
+ * The query type plugin manager.
* @param \Drupal\facets\Widget\WidgetPluginManager $widget_plugin_manager
+ * The widget plugin manager.
* @param \Drupal\facets\FacetSource\FacetSourcePluginManager $facet_source_manager
+ * The facet source plugin manager.
* @param \Drupal\facets\Processor\ProcessorPluginManager $processor_plugin_manager
+ * The processor plugin manager.
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
+ * The entity type plugin manager.
*/
public function __construct(QueryTypePluginManager $query_type_plugin_manager, WidgetPluginManager $widget_plugin_manager, FacetSourcePluginManager $facet_source_manager, ProcessorPluginManager $processor_plugin_manager, EntityTypeManager $entity_type_manager) {
- $this->query_type_plugin_manager = $query_type_plugin_manager;
+ $this->queryTypePluginManager = $query_type_plugin_manager;
$this->widget_plugin_manager = $widget_plugin_manager;
- $this->facet_source_manager = $facet_source_manager;
- $this->processor_plugin_manager = $processor_plugin_manager;
+ $this->facetSourcePluginManager = $facet_source_manager;
+ $this->processorPluginManager = $processor_plugin_manager;
$this->facet_storage = $entity_type_manager->getStorage('facets_facet');
// Immediately initialize the facets. This can be done directly because the
@@ -142,9 +151,9 @@ class DefaultFacetManager {
foreach ($this->facets as $facet) {
// Make sure we don't alter queries for facets with a different source.
- if ($facet->getFacetSourceId() == $this->facetsource_id) {
+ if ($facet->getFacetSourceId() == $this->facetSourceId) {
/** @var \Drupal\facets\QueryType\QueryTypeInterface $query_type_plugin */
- $query_type_plugin = $this->query_type_plugin_manager->createInstance($facet->getQueryType(), ['query' => $query, 'facet' => $facet]);
+ $query_type_plugin = $this->queryTypePluginManager->createInstance($facet->getQueryType(), ['query' => $query, 'facet' => $facet]);
$query_type_plugin->execute();
}
}
@@ -164,9 +173,10 @@ class DefaultFacetManager {
* Get the ID of the facet source.
*
* @return string
+ * The id of the facet source.
*/
- public function getFacetsourceId() {
- return $this->facetsource_id;
+ public function getFacetSourceId() {
+ return $this->facetSourceId;
}
/**
@@ -201,7 +211,7 @@ class DefaultFacetManager {
$processor_definition = $processor->getPluginDefinition();
if (is_array($processor_definition['stages']) && array_key_exists(ProcessorInterface::STAGE_PRE_QUERY, $processor_definition['stages'])) {
/** @var PreQueryProcessorInterface $pre_query_processor */
- $pre_query_processor = $this->processor_plugin_manager->createInstance($processor->getPluginDefinition()['id']);
+ $pre_query_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id']);
if (!$pre_query_processor instanceof PreQueryProcessorInterface) {
throw new InvalidProcessorException(new FormattableMarkup("The processor @processor has a pre_query definition but doesn't implement the required PreQueryProcessorInterface interface", ['@processor' => $processor_configuration['processor_id']]));
}
@@ -224,6 +234,7 @@ class DefaultFacetManager {
* BuildProcessorInterface enabled on this facet will run.
*
* @param \Drupal\facets\FacetInterface $facet
+ * The facet we should build.
*
* @return array
* Facet render arrays.
@@ -236,7 +247,7 @@ class DefaultFacetManager {
$facet = $this->facets[$facet->id()];
// @TODO: inject the searcher id on create of the FacetManager.
- $this->facetsource_id = $facet->getFacetSourceId();
+ $this->facetSourceId = $facet->getFacetSourceId();
if ($facet->getOnlyVisibleWhenFacetSourceIsVisible()) {
// Block rendering and processing should be stopped when the facet source
@@ -261,10 +272,10 @@ class DefaultFacetManager {
$results = $facet->getResults();
foreach ($facet->getProcessors() as $processor) {
- $processor_definition = $this->processor_plugin_manager->getDefinition($processor->getPluginDefinition()['id']);
+ $processor_definition = $this->processorPluginManager->getDefinition($processor->getPluginDefinition()['id']);
if (is_array($processor_definition['stages']) && array_key_exists(ProcessorInterface::STAGE_BUILD, $processor_definition['stages'])) {
/** @var BuildProcessorInterface $build_processor */
- $build_processor = $this->processor_plugin_manager->createInstance($processor->getPluginDefinition()['id']);
+ $build_processor = $this->processorPluginManager->createInstance($processor->getPluginDefinition()['id']);
if (!$build_processor instanceof BuildProcessorInterface) {
throw new InvalidProcessorException(new FormattableMarkup("The processor @processor has a build definition but doesn't implement the required BuildProcessorInterface interface", ['@processor' => $processor['processor_id']]));
}
@@ -277,9 +288,10 @@ class DefaultFacetManager {
// settings.
if (empty($facet->getResults())) {
$empty_behavior = $facet->getOption('empty_behavior');
- if($empty_behavior['behavior'] == 'text'){
+ if ($empty_behavior['behavior'] == 'text') {
return ['#markup' => $empty_behavior['text']];
- }else{
+ }
+ else {
return;
}
}
@@ -297,7 +309,7 @@ class DefaultFacetManager {
public function updateResults() {
// Get an instance of the facet source.
/** @var \drupal\facets\FacetSource\FacetSourceInterface $facet_source_plugin */
- $facet_source_plugin = $this->facet_source_manager->createInstance($this->facetsource_id);
+ $facet_source_plugin = $this->facetSourcePluginManager->createInstance($this->facetSourceId);
$facet_source_plugin->fillFacetsWithResults($this->facets);
}
diff --git a/src/FacetSource/FacetSourceDeriverBase.php b/src/FacetSource/FacetSourceDeriverBase.php
index f28d32b11e2d0c3a1e9eaa403a6e29fbb813e812..379760690560699279633d13d3c2c8804ba0507a 100644
--- a/src/FacetSource/FacetSourceDeriverBase.php
+++ b/src/FacetSource/FacetSourceDeriverBase.php
@@ -12,8 +12,9 @@ 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 {
diff --git a/src/FacetSource/FacetSourceInterface.php b/src/FacetSource/FacetSourceInterface.php
index 20cdb3279bb101429d6444fad7a1a4fd57590678..aef8c7a6b32e0f7e896d6c3a0b4ee9e4a5ab46ac 100644
--- a/src/FacetSource/FacetSourceInterface.php
+++ b/src/FacetSource/FacetSourceInterface.php
@@ -25,9 +25,13 @@ interface FacetSourceInterface {
* Adds a configuration form for this facet source.
*
* @param array $form
+ * The configuration form definition.
* @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current form state.
* @param \Drupal\facets\FacetInterface $facet
+ * The facet being edited.
* @param \Drupal\facets\FacetSource\FacetSourceInterface $facet_source
+ * The facet source being edited.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet, FacetSourceInterface $facet_source);
@@ -35,8 +39,7 @@ interface FacetSourceInterface {
* Fill in facet data in to the configured facets.
*
* @param \Drupal\facets\FacetInterface[] $facets
- *
- * @return mixed
+ * The configured facets.
*/
public function fillFacetsWithResults($facets);
@@ -44,6 +47,7 @@ interface FacetSourceInterface {
* Returns the path where a facet should link to.
*
* @return string
+ * The path of the facet.
*/
public function getPath();
@@ -51,10 +55,13 @@ interface FacetSourceInterface {
* Get the allowed query types for a given facet for the facet source.
*
* @param \Drupal\facets\FacetInterface $facet
+ * The facet we should get query types for.
*
- * @return array of allowed query types
+ * @return string[]
+ * array of allowed query types
*
* @throws \Drupal\facets\Exception\Exception
+ * An error when no query types are found.
*/
public function getQueryTypesForFacet(FacetInterface $facet);
@@ -65,7 +72,8 @@ interface FacetSourceInterface {
* when facet source visibility: "being rendered" is configured in the facet
* visibility settings.
*
- * @return boolean
+ * @return bool
+ * True when the facet is rendered on the same page.
*/
public function isRenderedInCurrentRequest();
@@ -76,6 +84,7 @@ interface FacetSourceInterface {
* is keyed by the field's machine name and has values of the field's label.
*
* @return array
+ * An array of available fields.
*/
public function getFields();
diff --git a/src/FacetSource/FacetSourcePluginBase.php b/src/FacetSource/FacetSourcePluginBase.php
index a87853e089a0c93357ec5e17f832134c20632fc0..127b72168389d8dfdbc6c8d4aa9ecbd771be90a8 100644
--- a/src/FacetSource/FacetSourcePluginBase.php
+++ b/src/FacetSource/FacetSourcePluginBase.php
@@ -1,6 +1,6 @@
keys;
}
+
}
diff --git a/src/Form/FacetDeleteConfirmForm.php b/src/Form/FacetDeleteConfirmForm.php
index 43a10793c39773507b5ce7503dcbdf9c9e9e542f..134cd2cdd8d98d5d2aeab09dc920d881d6441bf7 100644
--- a/src/Form/FacetDeleteConfirmForm.php
+++ b/src/Form/FacetDeleteConfirmForm.php
@@ -7,7 +7,6 @@
namespace Drupal\facets\Form;
-use Drupal\block\Entity\Block;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
@@ -53,4 +52,5 @@ class FacetDeleteConfirmForm extends EntityConfirmFormBase {
drupal_set_message($this->t('The facet %name has been deleted.', array('%name' => $this->entity->label())));
$form_state->setRedirect('facets.overview');
}
+
}
diff --git a/src/Form/FacetDisplayForm.php b/src/Form/FacetDisplayForm.php
index acee508f985d81ce00f96758f04b921058cbce3f..d55dfe1c7532f6826e98b617756ce9ea5a0e7f6c 100644
--- a/src/Form/FacetDisplayForm.php
+++ b/src/Form/FacetDisplayForm.php
@@ -58,13 +58,13 @@ class FacetDisplayForm extends EntityForm {
* The entity manager.
* @param \Drupal\facets\Processor\ProcessorPluginManager $processor_plugin_manager
* The processor plugin manager.
- * @param \Drupal\facets\Widget\WidgetPluginManager $widgetPluginManager
+ * @param \Drupal\facets\Widget\WidgetPluginManager $widget_plugin_manager
* The plugin manager for widgets.
*/
- public function __construct(EntityTypeManager $entity_type_manager, ProcessorPluginManager $processor_plugin_manager, WidgetPluginManager $widgetPluginManager) {
+ public function __construct(EntityTypeManager $entity_type_manager, ProcessorPluginManager $processor_plugin_manager, WidgetPluginManager $widget_plugin_manager) {
$this->entityTypeManager = $entity_type_manager;
$this->processorPluginManager = $processor_plugin_manager;
- $this->widgetPluginManager = $widgetPluginManager;
+ $this->widgetPluginManager = $widget_plugin_manager;
}
/**
@@ -86,7 +86,7 @@ class FacetDisplayForm extends EntityForm {
/**
* {@inheritdoc}
*/
- public function getBaseFormID() {
+ public function getBaseFormId() {
return NULL;
}
@@ -207,16 +207,19 @@ class FacetDisplayForm extends EntityForm {
$form['#attached']['library'][] = 'search_api/drupal.search_api.index-active-formatters';
$form['#title'] = $this->t('Manage processors for facet %label', array('%label' => $facet->label()));
- // Add the list of all other processors with checkboxes to enable/disable them.
+ // Add the list of all other processors with checkboxes to enable/disable
+ // them.
$form['facet_settings'] = array(
'#type' => 'fieldset',
'#title' => $this->t('Facet settings'),
- '#attributes' => array('class' => array(
- 'search-api-status-wrapper',
- )),
+ '#attributes' => array(
+ 'class' => array(
+ 'search-api-status-wrapper',
+ ),
+ ),
);
foreach ($all_processors as $processor_id => $processor) {
- if(!($processor instanceof WidgetOrderProcessorInterface)){
+ if (!($processor instanceof WidgetOrderProcessorInterface)) {
$clean_css_id = Html::cleanCssIdentifier($processor_id);
$form['facet_settings'][$processor_id]['status'] = array(
'#type' => 'checkbox',
@@ -233,18 +236,23 @@ class FacetDisplayForm extends EntityForm {
'#access' => !$processor->isHidden(),
);
- $processor_form_state = new SubFormState($form_state, array('facet_settings', $processor_id, 'settings'));
+ $processor_form_state = new SubFormState(
+ $form_state,
+ ['facet_settings', $processor_id, 'settings']
+ );
$processor_form = $processor->buildConfigurationForm($form, $processor_form_state, $facet);
if ($processor_form) {
$form['facet_settings'][$processor_id]['settings'] = array(
'#type' => 'details',
'#title' => $this->t('%processor settings', ['%processor' => (string) $processor->getPluginDefinition()['label']]),
- '#open' => true,
- '#attributes' => array('class' => array(
- 'facets-processor-settings-' . Html::cleanCssIdentifier($processor_id),
- 'facets-processor-settings-facet',
- 'facets-processor-settings'
- ),),
+ '#open' => TRUE,
+ '#attributes' => array(
+ 'class' => array(
+ 'facets-processor-settings-' . Html::cleanCssIdentifier($processor_id),
+ 'facets-processor-settings-facet',
+ 'facets-processor-settings',
+ ),
+ ),
'#states' => array(
'visible' => array(
':input[name="facet_settings[' . $processor_id . '][status]"]' => array('checked' => TRUE),
@@ -255,16 +263,19 @@ class FacetDisplayForm extends EntityForm {
}
}
}
- // Add the list of widget sort processors with checkboxes to enable/disable them.
+ // Add the list of widget sort processors with checkboxes to enable/disable
+ // them.
$form['facet_sorting'] = array(
'#type' => 'fieldset',
'#title' => $this->t('Facet sorting'),
- '#attributes' => array('class' => array(
- 'search-api-status-wrapper',
- )),
+ '#attributes' => array(
+ 'class' => array(
+ 'search-api-status-wrapper',
+ ),
+ ),
);
foreach ($all_processors as $processor_id => $processor) {
- if($processor instanceof WidgetOrderProcessorInterface){
+ if ($processor instanceof WidgetOrderProcessorInterface) {
$clean_css_id = Html::cleanCssIdentifier($processor_id);
$form['facet_sorting'][$processor_id]['status'] = array(
'#type' => 'checkbox',
@@ -281,18 +292,22 @@ class FacetDisplayForm extends EntityForm {
'#access' => !$processor->isHidden(),
);
- $processor_form_state = new SubFormState($form_state, array('facet_sorting', $processor_id, 'settings'));
+ $processor_form_state = new SubFormState(
+ $form_state,
+ array('facet_sorting', $processor_id, 'settings')
+ );
$processor_form = $processor->buildConfigurationForm($form, $processor_form_state, $facet);
if ($processor_form) {
$form['facet_sorting'][$processor_id]['settings'] = array(
'#type' => 'container',
-// '#title' => $this->t('%processor settings', ['%processor' => (string) $processor->getPluginDefinition()['label']]),
- '#open' => true,
- '#attributes' => array('class' => array(
- 'facets-processor-settings-' . Html::cleanCssIdentifier($processor_id),
- 'facets-processor-settings-sorting',
- 'facets-processor-settings'
- ),),
+ '#open' => TRUE,
+ '#attributes' => array(
+ 'class' => array(
+ 'facets-processor-settings-' . Html::cleanCssIdentifier($processor_id),
+ 'facets-processor-settings-sorting',
+ 'facets-processor-settings',
+ ),
+ ),
'#states' => array(
'visible' => array(
':input[name="facet_sorting[' . $processor_id . '][status]"]' => array('checked' => TRUE),
@@ -321,7 +336,7 @@ class FacetDisplayForm extends EntityForm {
'#description' => $this->t('The action to take when a facet has no items.'),
'#required' => TRUE,
];
- $form['facet_settings']['empty_behavior_container']= [
+ $form['facet_settings']['empty_behavior_container'] = [
'#type' => 'container',
'#states' => array(
'visible' => array(
@@ -333,7 +348,7 @@ class FacetDisplayForm extends EntityForm {
'#type' => 'text_format',
'#title' => $this->t('Empty text'),
'#format' => isset($empty_behavior_config['text_format']) ? $empty_behavior_config['text_format'] : 'plain_text',
- '#editor' => true,
+ '#editor' => TRUE,
'#default_value' => isset($empty_behavior_config['text_format']) ? $empty_behavior_config['text'] : '',
];
@@ -349,13 +364,15 @@ class FacetDisplayForm extends EntityForm {
// Order enabled processors per stage, create all the containers for the
// different stages.
foreach ($stages as $stage => $description) {
- $form['weights'][$stage] = array (
+ $form['weights'][$stage] = array(
'#type' => 'fieldset',
'#title' => $description['label'],
- '#attributes' => array('class' => array(
- 'search-api-stage-wrapper',
- 'search-api-stage-wrapper-' . Html::cleanCssIdentifier($stage),
- )),
+ '#attributes' => array(
+ 'class' => array(
+ 'search-api-stage-wrapper',
+ 'search-api-stage-wrapper-' . Html::cleanCssIdentifier($stage),
+ ),
+ ),
);
$form['weights'][$stage]['order'] = array(
'#type' => 'table',
@@ -392,9 +409,11 @@ class FacetDisplayForm extends EntityForm {
'#title_display' => 'invisible',
'#default_value' => $weight,
'#parents' => array('processors', $processor_id, 'weights', $stage),
- '#attributes' => array('class' => array(
- 'search-api-processor-weight-' . Html::cleanCssIdentifier($stage),
- )),
+ '#attributes' => array(
+ 'class' => array(
+ 'search-api-processor-weight-' . Html::cleanCssIdentifier($stage),
+ ),
+ ),
);
}
}
@@ -426,14 +445,20 @@ class FacetDisplayForm extends EntityForm {
// Iterate over all processors that have a form and are enabled.
foreach ($form['facet_settings'] as $processor_id => $processor_form) {
if (!empty($values['processors'][$processor_id])) {
- $processor_form_state = new SubFormState($form_state, array('facet_settings', $processor_id, 'settings'));
+ $processor_form_state = new SubFormState(
+ $form_state,
+ array('facet_settings', $processor_id, 'settings')
+ );
$processors[$processor_id]->validateConfigurationForm($form['facet_settings'][$processor_id], $processor_form_state, $facet);
}
}
// Iterate over all sorting processors that have a form and are enabled.
foreach ($form['facet_sorting'] as $processor_id => $processor_form) {
if (!empty($values['processors'][$processor_id])) {
- $processor_form_state = new SubFormState($form_state, array('facet_sorting', $processor_id, 'settings'));
+ $processor_form_state = new SubFormState(
+ $form_state,
+ array('facet_sorting', $processor_id, 'settings')
+ );
$processors[$processor_id]->validateConfigurationForm($form['facet_sorting'][$processor_id], $processor_form_state, $facet);
}
}
@@ -449,7 +474,6 @@ class FacetDisplayForm extends EntityForm {
// Store processor settings.
// @todo Go through all available processors, enable/disable with method on
// processor plugin to allow reaction.
-
/** @var \Drupal\facets\FacetInterface $facet */
$facet = $this->entity;
@@ -470,26 +494,38 @@ class FacetDisplayForm extends EntityForm {
$new_settings[$processor_id]['weights'] = $processor_values['weights'];
}
if (isset($form[$form_container_key][$processor_id]['settings'])) {
- $processor_form_state = new SubFormState($form_state, array($form_container_key, $processor_id, 'settings'));
+ $processor_form_state = new SubFormState(
+ $form_state,
+ array($form_container_key, $processor_id, 'settings')
+ );
$processor->submitConfigurationForm($form[$form_container_key][$processor_id]['settings'], $processor_form_state, $facet);
$new_settings[$processor_id]['settings'] = $processor->getConfiguration();
}
}
-
// Sort the processors so we won't have unnecessary changes.
ksort($new_settings);
$facet->setOption('processors', $new_settings);
$facet->setWidget($form_state->getValue('widget'));
$facet->set('widget_configs', $form_state->getValue('widget_configs'));
- $facet->set('only_visible_when_facet_source_is_visible', $form_state->getValue(['facet_settings','only_visible_when_facet_source_is_visible']));
+ $facet->set('only_visible_when_facet_source_is_visible', $form_state->getValue(['facet_settings', 'only_visible_when_facet_source_is_visible']));
$empty_behavior_config = [];
$empty_behavior = $form_state->getValue(['facet_settings', 'empty_behavior']);
$empty_behavior_config['behavior'] = $empty_behavior;
- if($empty_behavior == 'text'){
- $empty_behavior_config['text_format'] = $form_state->getValue(['facet_settings', 'empty_behavior_container', 'empty_behavior_text', 'format']);
- $empty_behavior_config['text'] = $form_state->getValue(['facet_settings', 'empty_behavior_container', 'empty_behavior_text', 'value']);
+ if ($empty_behavior == 'text') {
+ $empty_behavior_config['text_format'] = $form_state->getValue([
+ 'facet_settings',
+ 'empty_behavior_container',
+ 'empty_behavior_text',
+ 'format',
+ ]);
+ $empty_behavior_config['text'] = $form_state->getValue([
+ 'facet_settings',
+ 'empty_behavior_container',
+ 'empty_behavior_text',
+ 'value',
+ ]);
}
$facet->setOption('empty_behavior', $empty_behavior_config);
diff --git a/src/Form/FacetForm.php b/src/Form/FacetForm.php
index 2326131baa3db680eb68d89a1d666935736f7e44..59d8e9a08be10514d67967f4698af278bcde0778 100644
--- a/src/Form/FacetForm.php
+++ b/src/Form/FacetForm.php
@@ -10,7 +10,6 @@ namespace Drupal\facets\Form;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\FormStateInterface;
-use Drupal\facets\Exception\Exception;
use Drupal\facets\FacetInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\facets\Processor\ProcessorPluginManager;
@@ -48,15 +47,15 @@ class FacetForm extends EntityForm {
*
* @param \Drupal\Core\Entity\EntityTypeManager $entity_type_manager
* The entity manager.
- * @param \Drupal\facets\FacetSource\FacetSourcePluginManager $facetSourcePluginManager
+ * @param \Drupal\facets\FacetSource\FacetSourcePluginManager $facet_source_plugin_manager
* The plugin manager for facet sources.
- * @param \Drupal\facets\Processor\ProcessorPluginManager $processorPluginManager
+ * @param \Drupal\facets\Processor\ProcessorPluginManager $processor_plugin_manager
* The plugin manager for processors.
*/
- public function __construct(EntityTypeManager $entity_type_manager, FacetSourcePluginManager $facetSourcePluginManager, ProcessorPluginManager $processorPluginManager) {
+ public function __construct(EntityTypeManager $entity_type_manager, FacetSourcePluginManager $facet_source_plugin_manager, ProcessorPluginManager $processor_plugin_manager) {
$this->facetStorage = $entity_type_manager->getStorage('facets_facet');
- $this->facetSourcePluginManager = $facetSourcePluginManager;
- $this->processorPluginManager = $processorPluginManager;
+ $this->facetSourcePluginManager = $facet_source_plugin_manager;
+ $this->processorPluginManager = $processor_plugin_manager;
}
/**
@@ -214,8 +213,6 @@ class FacetForm extends EntityForm {
];
$this->buildFacetSourceConfigForm($form, $form_state);
-
-
$form['status'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enabled'),
@@ -287,8 +284,8 @@ class FacetForm extends EntityForm {
foreach ($processors_definitions as $processor_id => $processor) {
if (isset($processor['locked']) && $processor['locked'] == TRUE) {
$weights = [];
- foreach($stages as $stage_id => $stage) {
- if(isset($processor['stages'][$stage_id])) {
+ foreach ($stages as $stage_id => $stage) {
+ if (isset($processor['stages'][$stage_id])) {
$weights[$stage_id] = $processor['stages'][$stage_id];
}
}
@@ -304,7 +301,7 @@ class FacetForm extends EntityForm {
// Set a default widget for new facets.
$facet->setWidget('links');
- // Set default empty behaviour
+ // Set default empty behaviour.
$facet->setOption('empty_behavior', ['behavior' => 'none']);
$facet->setOnlyVisibleWhenFacetSourceIsVisible(TRUE);
}
@@ -341,7 +338,8 @@ class FacetForm extends EntityForm {
drupal_set_message($message);
$form_state->setRedirect('entity.facets_facet.display_form', ['facets_facet' => $facet->id()]);
}
- }else{
+ }
+ else {
drupal_set_message(t('Facet %name has been updated.', ['%name' => $facet->getName()]));
}
diff --git a/src/Form/SubFormState.php b/src/Form/SubFormState.php
index 1dbb75b20bd912f416f4de8df4f4909a7d13e8eb..319e1b5ab03e7eeafd8860ec292ce45bb9f6b6b7 100644
--- a/src/Form/SubFormState.php
+++ b/src/Form/SubFormState.php
@@ -515,8 +515,9 @@ class SubFormState implements FormStateInterface {
/**
* {@inheritdoc}
+ *
+ * @todo What are groups? Is this the way to handle them in a sub-form?
*/
- // @todo What are groups? Is this the way to handle them in a sub-form?
public function setGroups(array $groups) {
$this->mainFormState->setGroups($groups);
return $this;
diff --git a/src/Plugin/Block/FacetBlock.php b/src/Plugin/Block/FacetBlock.php
index 92b17d9b8eb3224e25bb3645bb1080a170a1bf1f..bab4d4b322e62f71c21d9fe76b0c3b1d9c63e4ff 100644
--- a/src/Plugin/Block/FacetBlock.php
+++ b/src/Plugin/Block/FacetBlock.php
@@ -12,7 +12,7 @@ namespace Drupal\facets\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
-use Drupal\facetapi\Entity\Facet;
+use Drupal\facets\FacetManager\DefaultFacetManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
@@ -25,14 +25,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* "facet" = @ContextDefinition("entity:facets_facet", label=@Translation("Facet"))
* }
* )
- *
*/
class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
/**
* The facet_manager plugin manager.
*
- * @var \Drupal\facets\FacetManager\DefaultFacetManager
+ * @var DefaultFacetManager
*/
protected $facetManager;
@@ -45,10 +44,11 @@ class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
* The plugin_id for the plugin instance.
* @param string $plugin_definition
* The plugin implementation definition.
- * @param \Drupal\facets\FacetManager\DefaultFacetManager $facetManager
+ * @param \Drupal\facets\FacetManager\DefaultFacetManager $facet_manager
+ * The facet manager service.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, \Drupal\facets\FacetManager\DefaultFacetManager $facetManager) {
- $this->facetManager = $facetManager;
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, DefaultFacetManager $facet_manager) {
+ $this->facetManager = $facet_manager;
parent::__construct($configuration, $plugin_id, $plugin_definition);
}
@@ -57,14 +57,14 @@ class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
- /** @var \Drupal\facets\FacetManager\DefaultFacetManager $facetManager */
- $facetManager = $container->get('facets.manager');
+ /** @var \Drupal\facets\FacetManager\DefaultFacetManager $facet_manager */
+ $facet_manager = $container->get('facets.manager');
return new static(
$configuration,
$plugin_id,
$plugin_definition,
- $facetManager
+ $facet_manager
);
}
diff --git a/src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php b/src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php
index 22b53df1f128d9a399e269cdbaeb8d712e963f4e..b7f86d51ca71f65d1c49908d7ba0720b526359ff 100644
--- a/src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php
+++ b/src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php
@@ -15,8 +15,9 @@ use Drupal\facets\FacetSource\FacetSourceInterface;
use Drupal\facets\FacetSource\FacetSourcePluginBase;
use Drupal\search_api\FacetsQueryTypeMappingInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+
/**
- *
+ * A base class for Search API facet sources.
*/
abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
@@ -121,7 +122,6 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
*
* @param \Drupal\search_api\Backend\BackendInterface $backend
* The backend that we want to get the query types for.
- *
* @param string $data_type_plugin_id
* The identifier of the data type.
*
diff --git a/src/Plugin/facets/facet_source/SearchApiViewsPageDeriver.php b/src/Plugin/facets/facet_source/SearchApiViewsPageDeriver.php
index e70e4e0fee15c69d366f8987834e444128089d7c..ac85ac506f46b2f9b1c445d0f790d1afb6670010 100644
--- a/src/Plugin/facets/facet_source/SearchApiViewsPageDeriver.php
+++ b/src/Plugin/facets/facet_source/SearchApiViewsPageDeriver.php
@@ -35,15 +35,15 @@ class SearchApiViewsPageDeriver extends FacetSourceDeriverBase {
if (strpos($view->get('base_table'), 'search_api_index') !== FALSE) {
$displays = $view->get('display');
foreach ($displays as $name => $display_info) {
- if($display_info['display_plugin'] == "page"){
+ if ($display_info['display_plugin'] == "page") {
$machine_name = $view->id() . PluginBase::DERIVATIVE_SEPARATOR . $name;
$plugin_derivatives[$machine_name] = [
- 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
- 'label' => $this->t('Search api view: %view_name, display: %display_title', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]),
- 'description' => $this->t('Provides a facet source.'),
- 'view_id' => $view->id(),
- 'view_display' => $name,
+ 'id' => $base_plugin_id . PluginBase::DERIVATIVE_SEPARATOR . $machine_name,
+ 'label' => $this->t('Search api view: %view_name, display: %display_title', ['%view_name' => $view->label(), '%display_title' => $display_info['display_title']]),
+ 'description' => $this->t('Provides a facet source.'),
+ 'view_id' => $view->id(),
+ 'view_display' => $name,
] + $base_plugin_definition;
$sources[] = $this->t('Search api view: ' . $view->label() . ' display: ' . $display_info['display_title']);
diff --git a/src/Plugin/facets/processor/ActiveWidgetOrderProcessor.php b/src/Plugin/facets/processor/ActiveWidgetOrderProcessor.php
index e779e79b68352754b44171c6a3b174143b5be58f..2b125c7a01b2c65288020a1fee005bdea85fccdf 100644
--- a/src/Plugin/facets/processor/ActiveWidgetOrderProcessor.php
+++ b/src/Plugin/facets/processor/ActiveWidgetOrderProcessor.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\processor\ActiveWidgetOrderProcessor.
*/
namespace Drupal\facets\Plugin\facets\processor;
@@ -12,6 +13,8 @@ use Drupal\facets\Processor\WidgetOrderProcessorInterface;
use Drupal\facets\Result\Result;
/**
+ * A processor that orders the results by active state.
+ *
* @FacetsProcessor(
* id = "active_widget_order",
* label = @Translation("Sort by active state"),
@@ -38,7 +41,7 @@ class ActiveWidgetOrderProcessor extends WidgetOrderPluginBase implements Widget
}
/**
- *
+ * Sorts ascending.
*/
protected static function sortActiveAsc(Result $a, Result $b) {
if ($a->isActive() == $b->isActive()) {
@@ -48,7 +51,7 @@ class ActiveWidgetOrderProcessor extends WidgetOrderPluginBase implements Widget
}
/**
- *
+ * Sorts descending.
*/
protected static function sortActiveDesc(Result $a, Result $b) {
if ($a->isActive() == $b->isActive()) {
diff --git a/src/Plugin/facets/processor/CountLimitProcessor.php b/src/Plugin/facets/processor/CountLimitProcessor.php
index 30c2c1ee3c3e55a8b03fe5630743affcfe52b56e..284c8a649783c43f2723cca99c05a041abe6e821 100644
--- a/src/Plugin/facets/processor/CountLimitProcessor.php
+++ b/src/Plugin/facets/processor/CountLimitProcessor.php
@@ -50,7 +50,7 @@ class CountLimitProcessor extends ProcessorPluginBase implements BuildProcessorI
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
- $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null;
+ $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$build['minimum_items'] = array(
'#title' => $this->t('Minimum items'),
diff --git a/src/Plugin/facets/processor/CountWidgetOrderProcessor.php b/src/Plugin/facets/processor/CountWidgetOrderProcessor.php
index 73cb7193d842cd79b0e543f6720f14f0086c23cb..f28f71bbba8bfa0a9fc0ec95d79aa25b1eed9bbe 100644
--- a/src/Plugin/facets/processor/CountWidgetOrderProcessor.php
+++ b/src/Plugin/facets/processor/CountWidgetOrderProcessor.php
@@ -2,16 +2,18 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\processor\CountWidgetOrderProcessor.
*/
namespace Drupal\facets\Plugin\facets\processor;
-
use Drupal\facets\Processor\WidgetOrderPluginBase;
use Drupal\facets\Processor\WidgetOrderProcessorInterface;
use Drupal\facets\Result\Result;
/**
+ * A processor that orders the results by amount.
+ *
* @FacetsProcessor(
* id = "count_widget_order",
* label = @Translation("Sort by count"),
@@ -38,7 +40,7 @@ class CountWidgetOrderProcessor extends WidgetOrderPluginBase implements WidgetO
}
/**
- *
+ * Sorts ascending.
*/
protected static function sortCountAsc(Result $a, Result $b) {
if ($a->getCount() == $b->getCount()) {
@@ -48,7 +50,7 @@ class CountWidgetOrderProcessor extends WidgetOrderPluginBase implements WidgetO
}
/**
- *
+ * Sorts descending.
*/
protected static function sortCountDesc(Result $a, Result $b) {
if ($a->getCount() == $b->getCount()) {
diff --git a/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php b/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php
index 4fd406182611934130f8ea21fb3fefc6e77bd8c7..638ad73d028b294daf31ad5d0ad3c82c4572b86c 100644
--- a/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php
+++ b/src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\processor\DisplayValueWidgetOrderProcessor.
*/
namespace Drupal\facets\Plugin\facets\processor;
@@ -11,6 +12,8 @@ use Drupal\facets\Processor\WidgetOrderProcessorInterface;
use Drupal\facets\Result\Result;
/**
+ * A processor that orders the results by display value.
+ *
* @FacetsProcessor(
* id = "display_value_widget_order",
* label = @Translation("Sort by display value"),
@@ -37,14 +40,14 @@ class DisplayValueWidgetOrderProcessor extends WidgetOrderPluginBase implements
}
/**
- *
+ * Sorts ascending.
*/
protected static function sortDisplayValueAsc(Result $a, Result $b) {
return strnatcasecmp($a->getDisplayValue(), $b->getDisplayValue());
}
/**
- *
+ * Sorts descending.
*/
protected static function sortDisplayValueDesc(Result $a, Result $b) {
return strnatcasecmp($b->getDisplayValue(), $a->getDisplayValue());
diff --git a/src/Plugin/facets/processor/ExcludeSpecifiedItemsProcessor.php b/src/Plugin/facets/processor/ExcludeSpecifiedItemsProcessor.php
index 218af40619c76fabf95a6c6f43f69d5b29366acb..dd29b4e617db256993c65b56a8c46ff8102bd619 100644
--- a/src/Plugin/facets/processor/ExcludeSpecifiedItemsProcessor.php
+++ b/src/Plugin/facets/processor/ExcludeSpecifiedItemsProcessor.php
@@ -56,7 +56,7 @@ class ExcludeSpecifiedItemsProcessor extends ProcessorPluginBase implements Buil
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
- $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null;
+ $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$build['exclude'] = [
'#title' => $this->t('Exclude items'),
@@ -83,4 +83,5 @@ class ExcludeSpecifiedItemsProcessor extends ProcessorPluginBase implements Buil
'regex' => 0,
];
}
+
}
diff --git a/src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php b/src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php
index fcfc478313a2bb0b88d274e92ff1118139dfb6b6..4c5f99c141538afea4951dba3449c9067d4307ef 100644
--- a/src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php
+++ b/src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php
@@ -28,17 +28,17 @@ class HideNonNarrowingResultProcessor extends ProcessorPluginBase implements Bui
* {@inheritdoc}
*/
public function build(FacetInterface $facet, array $results) {
- $facetResults = $facet->getResults();
- $resultCount = 0;
- foreach ($facetResults as $result) {
+ $facet_results = $facet->getResults();
+ $result_count = 0;
+ foreach ($facet_results as $result) {
if ($result->isActive()) {
- $resultCount += $result->getCount();
+ $result_count += $result->getCount();
}
}
/** @var \Drupal\facets\Result\ResultInterface $result */
foreach ($results as $id => $result) {
- if ($result->getCount() == $resultCount && !$result->isActive()) {
+ if ($result->getCount() == $result_count && !$result->isActive()) {
unset($results[$id]);
}
}
diff --git a/src/Plugin/facets/processor/QueryStringUrlProcessor.php b/src/Plugin/facets/processor/QueryStringUrlProcessor.php
index 79cd1ef62ccf4e7969adfee4749a8781b4f242ea..1c7bbb5d0c702f094ff53dcd11bf9d845e02dafe 100644
--- a/src/Plugin/facets/processor/QueryStringUrlProcessor.php
+++ b/src/Plugin/facets/processor/QueryStringUrlProcessor.php
@@ -13,6 +13,8 @@ use Drupal\facets\Processor\UrlProcessorPluginBase;
use Symfony\Component\HttpFoundation\Request;
/**
+ * The basic url processor, uses query strings.
+ *
* @FacetsProcessor(
* id = "query_string",
* label = @Translation("Query string url processor"),
@@ -32,10 +34,12 @@ class QueryStringUrlProcessor extends UrlProcessorPluginBase {
const SEPARATOR = ':';
/**
- * @var array
+ * An array of active filters.
+ *
+ * @var string[]
* An array containing the active filters
*/
- protected $active_filters = [];
+ protected $activeFilters = [];
/**
* {@inheritdoc}
@@ -63,7 +67,7 @@ class QueryStringUrlProcessor extends UrlProcessorPluginBase {
$filter_string = $facet->getFieldAlias() . ':' . $result->getRawValue();
$result_get_params = clone $get_params;
- $filter_params = $result_get_params->get($this->filter_key, [], TRUE);
+ $filter_params = $result_get_params->get($this->filterKey, [], TRUE);
// If the value is active, remove the filter string from the parameters.
if ($result->isActive()) {
foreach ($filter_params as $key => $filter_param) {
@@ -77,7 +81,7 @@ class QueryStringUrlProcessor extends UrlProcessorPluginBase {
$filter_params[] = $filter_string;
}
- $result_get_params->set($this->filter_key, $filter_params);
+ $result_get_params->set($this->filterKey, $filter_params);
$request = $this->request;
if ($facet->getFacetSource()->getPath()) {
$request = Request::create('/' . $facet->getFacetSource()->getPath());
@@ -96,8 +100,8 @@ class QueryStringUrlProcessor extends UrlProcessorPluginBase {
*/
public function preQuery(FacetInterface $facet) {
// Get the filter key of the facet.
- if (isset($this->active_filters[$facet->getFieldAlias()])) {
- foreach ($this->active_filters[$facet->getFieldAlias()] as $value) {
+ if (isset($this->activeFilters[$facet->getFieldAlias()])) {
+ foreach ($this->activeFilters[$facet->getFieldAlias()] as $value) {
$facet->setActiveItem(trim($value, '"'));
}
}
@@ -114,16 +118,16 @@ class QueryStringUrlProcessor extends UrlProcessorPluginBase {
$url_parameters = $this->request->query;
// Get the active facet parameters.
- $active_params = $url_parameters->get($this->filter_key, array(), TRUE);
+ $active_params = $url_parameters->get($this->filterKey, array(), TRUE);
// Explode the active params on the separator.
foreach ($active_params as $param) {
list($key, $value) = explode(self::SEPARATOR, $param);
- if (!isset($this->active_filters[$key])) {
- $this->active_filters[$key] = [$value];
+ if (!isset($this->activeFilters[$key])) {
+ $this->activeFilters[$key] = [$value];
}
else {
- $this->active_filters[$key][] = $value;
+ $this->activeFilters[$key][] = $value;
}
}
}
diff --git a/src/Plugin/facets/processor/RawValueWidgetOrderProcessor.php b/src/Plugin/facets/processor/RawValueWidgetOrderProcessor.php
index 91068ca9e561878d7838f1ebd025883f955eeae0..f5c9787e04e854f5fe7ef522de565b07673c20f0 100644
--- a/src/Plugin/facets/processor/RawValueWidgetOrderProcessor.php
+++ b/src/Plugin/facets/processor/RawValueWidgetOrderProcessor.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\processor\RawValueWidgetOrderProcessor.
*/
namespace Drupal\facets\Plugin\facets\processor;
@@ -11,6 +12,8 @@ use Drupal\facets\Processor\WidgetOrderProcessorInterface;
use Drupal\facets\Result\Result;
/**
+ * A processor that orders the results by raw value.
+ *
* @FacetsProcessor(
* id = "raw_value_widget_order",
* label = @Translation("Sort by raw value"),
@@ -37,14 +40,14 @@ class RawValueWidgetOrderProcessor extends WidgetOrderPluginBase implements Widg
}
/**
- *
+ * Sorts ascending.
*/
protected static function sortRawValueAsc(Result $a, Result $b) {
return strnatcasecmp($a->getRawValue(), $b->getRawValue());
}
/**
- *
+ * Sorts descending.
*/
protected static function sortRawValueDesc(Result $a, Result $b) {
return strnatcasecmp($b->getRawValue(), $a->getRawValue());
diff --git a/src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php b/src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php
index d160e7d1a2beaaf9daff1313e7170a3d449f1682..608138dca13fa45b48b9167e88e2df5d1119b9da 100644
--- a/src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php
+++ b/src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php
@@ -6,14 +6,13 @@
namespace Drupal\facets\Plugin\facets\processor;
-use Drupal\Core\Entity\Entity;
use Drupal\facets\FacetInterface;
use Drupal\facets\Processor\BuildProcessorInterface;
use Drupal\facets\Processor\ProcessorPluginBase;
use Drupal\user\Entity\User;
/**
- * Provides a processor that transforms the results to show the user's name
+ * Provides a processor that transforms the results to show the user's name.
*
* @FacetsProcessor(
* id = "uid_to_username_callback",
diff --git a/src/Plugin/facets/widget/CheckboxWidget.php b/src/Plugin/facets/widget/CheckboxWidget.php
index 730a6be934a6d4ff0ac7edf6994d5ee8de92dad8..6d8bf49b0aeac8ac3e17dbb4d80afcbbeda951c6 100644
--- a/src/Plugin/facets/widget/CheckboxWidget.php
+++ b/src/Plugin/facets/widget/CheckboxWidget.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\widget\CheckboxWidget.
*/
namespace Drupal\facets\Plugin\facets\widget;
@@ -12,6 +13,8 @@ use Drupal\facets\FacetInterface;
use Drupal\facets\Widget\WidgetInterface;
/**
+ * The checkbox / radios widget.
+ *
* @FacetsWidget(
* id = "checkbox",
* label = @Translation("List of checkboxes"),
@@ -23,7 +26,10 @@ class CheckboxWidget implements WidgetInterface {
use StringTranslationTrait;
/**
+ * The link generator.
+ *
* @var \Drupal\Core\Utility\LinkGeneratorInterface $linkGenerator
+ * The link generator.
*/
protected $linkGenerator;
@@ -49,7 +55,7 @@ class CheckboxWidget implements WidgetInterface {
if ($result->getCount()) {
// Get the link.
$text = $result->getDisplayValue();
- if($show_numbers){
+ if ($show_numbers) {
$text .= ' (' . $result->getCount() . ')';
}
if ($result->isActive()) {
@@ -99,6 +105,7 @@ class CheckboxWidget implements WidgetInterface {
* Gets the link generator.
*
* @return \Drupal\Core\Utility\LinkGeneratorInterface
+ * The link generator.
*/
protected function linkGenerator() {
if (!isset($this->linkGenerator)) {
@@ -106,4 +113,5 @@ class CheckboxWidget implements WidgetInterface {
}
return $this->linkGenerator;
}
+
}
diff --git a/src/Plugin/facets/widget/LinksWidget.php b/src/Plugin/facets/widget/LinksWidget.php
index 9290ce6dfb354c5909e53a7318b0b748daa279e9..196cd5ef051a0c3107a189cb144042caeb876028 100644
--- a/src/Plugin/facets/widget/LinksWidget.php
+++ b/src/Plugin/facets/widget/LinksWidget.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Plugin\facets\widget\LinksWidget.
*/
namespace Drupal\facets\Plugin\facets\widget;
@@ -12,20 +13,23 @@ use Drupal\facets\FacetInterface;
use Drupal\facets\Widget\WidgetInterface;
/**
+ * The links widget.
+ *
* @FacetsWidget(
* id = "links",
* label = @Translation("List of links"),
* description = @Translation("A simple widget that shows a list of links"),
* )
- *
- * Class LinksWidget
*/
class LinksWidget implements WidgetInterface {
use StringTranslationTrait;
/**
+ * The link generator.
+ *
* @var \Drupal\Core\Utility\LinkGeneratorInterface $linkGenerator
+ * The link generator.
*/
protected $linkGenerator;
@@ -107,6 +111,7 @@ class LinksWidget implements WidgetInterface {
* Gets the link generator.
*
* @return \Drupal\Core\Utility\LinkGeneratorInterface
+ * The link generator.
*/
protected function linkGenerator() {
if (!isset($this->linkGenerator)) {
diff --git a/src/Processor/BuildProcessorInterface.php b/src/Processor/BuildProcessorInterface.php
index 221df449d3c3c13883a5b9b1a0cb15b2c688a31f..d494f2776437c3f6b2ec79d97a0f30e09c58ffe0 100644
--- a/src/Processor/BuildProcessorInterface.php
+++ b/src/Processor/BuildProcessorInterface.php
@@ -4,6 +4,7 @@
* @file
* Contains \Drupal\facets\Processor\BuildProcessorInterface.
*/
+
namespace Drupal\facets\Processor;
use Drupal\facets\FacetInterface;
@@ -18,9 +19,12 @@ interface BuildProcessorInterface extends ProcessorInterface {
* Processor runs before the renderable array is created.
*
* @param \Drupal\facets\FacetInterface $facet
+ * The facet being changed.
* @param \Drupal\facets\Result\Result[] $results
+ * The results being changed.
*
* @return \Drupal\facets\Result\Result[] $results
+ * The changed results.
*/
public function build(FacetInterface $facet, array $results);
diff --git a/src/Processor/PostQueryProcessorInterface.php b/src/Processor/PostQueryProcessorInterface.php
index bf0224f8c7d8cb71aba1e5ae650af6e8c7c35a84..3a932064104d1d2eb935637bd6857c959bae6d09 100644
--- a/src/Processor/PostQueryProcessorInterface.php
+++ b/src/Processor/PostQueryProcessorInterface.php
@@ -4,6 +4,7 @@
* @file
* Contains \Drupal\facets\Processor\PostQueryProcessorInterface.
*/
+
namespace Drupal\facets\Processor;
@@ -19,6 +20,7 @@ interface PostQueryProcessorInterface extends ProcessorInterface {
* ValueCallbackProcessor.
*
* @param \Drupal\facets\Result\Result[] $results
+ * The results being changed.
*/
public function postQuery(array $results);
diff --git a/src/Processor/PreQueryProcessorInterface.php b/src/Processor/PreQueryProcessorInterface.php
index 840dd2eef1bdbbdf070a24a117c5b90b8e4b786b..72c854de7307e2b53322d0cdf44a2d2b716a703e 100644
--- a/src/Processor/PreQueryProcessorInterface.php
+++ b/src/Processor/PreQueryProcessorInterface.php
@@ -21,7 +21,8 @@ interface PreQueryProcessorInterface extends ProcessorInterface {
* alteration to the query was added before the query is executed in the
* backend?
*
- * @param \Drupal\facets\FacetInterface $queryType
+ * @param \Drupal\facets\FacetInterface $facet
+ * The facet being changed.
*/
public function preQuery(FacetInterface $facet);
diff --git a/src/Processor/ProcessorInterface.php b/src/Processor/ProcessorInterface.php
index c8ecfe8398044be82faa08971ffd5fda4926d976..6ce95014de953da20c2e6b59df7859260c7f5d86 100644
--- a/src/Processor/ProcessorInterface.php
+++ b/src/Processor/ProcessorInterface.php
@@ -35,8 +35,11 @@ interface ProcessorInterface extends ConfigurablePluginInterface {
* Adds a configuration form for this processor.
*
* @param array $form
+ * The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current form state.
* @param \Drupal\facets\FacetInterface $facet
+ * The facet this processor is being added to.
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet);
@@ -44,8 +47,11 @@ interface ProcessorInterface extends ConfigurablePluginInterface {
* Validates a configuration form for this processor.
*
* @param array $form
+ * The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current form state.
* @param \Drupal\facets\FacetInterface $facet
+ * The facet this processor is being added to.
*/
public function validateConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet);
diff --git a/src/Processor/ProcessorPluginBase.php b/src/Processor/ProcessorPluginBase.php
index 92788f363394ed6a7e1fda553bfee9c75b503eb5..c5221b0f11aa6405384f5062061a5d7e3156cc4a 100644
--- a/src/Processor/ProcessorPluginBase.php
+++ b/src/Processor/ProcessorPluginBase.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains Drupal\facets\Processor\ProcessorPluginBase.
*/
namespace Drupal\facets\Processor;
@@ -28,7 +29,6 @@ class ProcessorPluginBase extends PluginBase implements ProcessorInterface {
* {@inheritdoc}
*/
public function validateConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
- return;
}
/**
diff --git a/src/Processor/UrlProcessorPluginBase.php b/src/Processor/UrlProcessorPluginBase.php
index 7651da88e2e463ab98564a49113aca96374658ff..ee8af0b9b3ddbd0ea993191f1bb081866bb9cfe9 100644
--- a/src/Processor/UrlProcessorPluginBase.php
+++ b/src/Processor/UrlProcessorPluginBase.php
@@ -16,14 +16,18 @@ use Symfony\Component\HttpFoundation\Request;
abstract class UrlProcessorPluginBase extends ProcessorPluginBase implements UrlProcessorInterface, ContainerFactoryPluginInterface {
/**
+ * The query string variable.
+ *
* @var string
* The query string variable that holds all the facet information.
*/
- protected $filter_key = 'f';
+ protected $filterKey = 'f';
/**
+ * The current request object.
+ *
* @var Request
- * The current request.
+ * The current request object.
*/
protected $request;
@@ -31,16 +35,20 @@ abstract class UrlProcessorPluginBase extends ProcessorPluginBase implements Url
* {@inheritdoc}
*/
public function getFilterKey() {
- return $this->filter_key;
+ return $this->filterKey;
}
/**
* Constructs a new instance of the class.
*
* @param array $configuration
+ * A configuration array containing information about the plugin instance.
* @param string $plugin_id
+ * The plugin_id for the plugin instance.
* @param mixed $plugin_definition
+ * The plugin implementation definition.
* @param \Symfony\Component\HttpFoundation\Request $request
+ * A request object for the current request.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, Request $request) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
diff --git a/src/Processor/WidgetOrderPluginBase.php b/src/Processor/WidgetOrderPluginBase.php
index 425d3c8977f57bc01813bf0cbfe20fda3d56fa87..3014f6497fbb3afd3513ff4f0ab08eca7c52bd2d 100644
--- a/src/Processor/WidgetOrderPluginBase.php
+++ b/src/Processor/WidgetOrderPluginBase.php
@@ -2,6 +2,7 @@
/**
* @file
+ * Contains \Drupal\facets\Processor\WidgetOrderPluginBase.
*/
namespace Drupal\facets\Processor;
@@ -19,7 +20,7 @@ abstract class WidgetOrderPluginBase extends ProcessorPluginBase implements Widg
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state, FacetInterface $facet) {
$processors = $facet->getProcessors();
- $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : null;
+ $config = isset($processors[$this->getPluginId()]) ? $processors[$this->getPluginId()] : NULL;
$build['sort'] = [
'#type' => 'radios',
diff --git a/src/Processor/WidgetOrderProcessorInterface.php b/src/Processor/WidgetOrderProcessorInterface.php
index d7532a6dc2bd0874d419b8ba646022cd71aaf47f..e07c84d98b15e3fd82a84b2ea91470c98d223fdb 100644
--- a/src/Processor/WidgetOrderProcessorInterface.php
+++ b/src/Processor/WidgetOrderProcessorInterface.php
@@ -16,10 +16,10 @@ interface WidgetOrderProcessorInterface extends BuildProcessorInterface {
* Order results and return the new order of results.
*
* @param \Drupal\facets\Result\Result[] $results
- * An array containing results
+ * An array containing results.
* @param string $order
* A string denoting the order in which we should sort, either 'ASC' or
- * 'DESC'
+ * 'DESC'.
*
* @return \Drupal\facets\Result\Result[]
* The same array that was passed in, ordered by $order
diff --git a/src/QueryType/QueryTypeInterface.php b/src/QueryType/QueryTypeInterface.php
index bb4f76136eebb7dcd669693dcd3aaa2ea77f21d6..e4a9ed3bcdcffda6b34865b576ea5693f3e25f88 100644
--- a/src/QueryType/QueryTypeInterface.php
+++ b/src/QueryType/QueryTypeInterface.php
@@ -13,8 +13,6 @@ interface QueryTypeInterface {
/**
* Add facet info to the query using the backend native query object.
- *
- * @return mixed
*/
public function execute();
diff --git a/src/QueryType/QueryTypePluginBase.php b/src/QueryType/QueryTypePluginBase.php
index fe4010c4b15ddb1dec61ff59527007c42e4d33d0..497a7f27eebd12fbd900ebd5ab39e9f467e77f02 100644
--- a/src/QueryType/QueryTypePluginBase.php
+++ b/src/QueryType/QueryTypePluginBase.php
@@ -53,7 +53,7 @@ abstract class QueryTypePluginBase extends PluginBase implements QueryTypeInterf
*
* @var \Drupal\Core\Utility\LinkGeneratorInterface
*/
- protected $link_generator;
+ protected $linkGenerator;
/**
* {@inheritdoc}
diff --git a/src/QueryType/QueryTypePluginManager.php b/src/QueryType/QueryTypePluginManager.php
index 1b817015b0407470ad42d9612dc97bcbf0d0707c..a64fcb1008b4250bc11457a582dafa7641db186a 100644
--- a/src/QueryType/QueryTypePluginManager.php
+++ b/src/QueryType/QueryTypePluginManager.php
@@ -12,7 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
- * Defines a plugin manager for query types
+ * Defines a plugin manager for query types.
*/
class QueryTypePluginManager extends DefaultPluginManager {
diff --git a/src/Result/Result.php b/src/Result/Result.php
index f7e436a35cf44c1d61b98961ce562bc07453b182..f430981f440df6e2b1a2311907b5cd33b20d0553 100644
--- a/src/Result/Result.php
+++ b/src/Result/Result.php
@@ -16,12 +16,12 @@ class Result implements ResultInterface {
/**
* The facet value.
*/
- protected $display_value;
+ protected $displayValue;
/**
* The raw facet value.
*/
- protected $raw_value;
+ protected $rawValue;
/**
* The facet count.
@@ -47,13 +47,16 @@ class Result implements ResultInterface {
/**
* Construct a new instance of the value object.
*
- * @param $raw_value
- * @param $display_value
- * @param $count
+ * @param mixed $raw_value
+ * The raw value.
+ * @param mixed $display_value
+ * The formatted value.
+ * @param int $count
+ * The amount of items.
*/
- function __construct($raw_value, $display_value, $count) {
- $this->raw_value = $raw_value;
- $this->display_value = $display_value;
+ public function __construct($raw_value, $display_value, $count) {
+ $this->rawValue = $raw_value;
+ $this->displayValue = $display_value;
$this->count = $count;
}
@@ -61,14 +64,14 @@ class Result implements ResultInterface {
* {@inheritdoc}
*/
public function getDisplayValue() {
- return $this->display_value;
+ return $this->displayValue;
}
/**
* {@inheritdoc}
*/
public function getRawValue() {
- return $this->raw_value;
+ return $this->rawValue;
}
/**
@@ -110,7 +113,7 @@ class Result implements ResultInterface {
* {@inheritdoc}
*/
public function setDisplayValue($display_value) {
- $this->display_value = $display_value;
+ $this->displayValue = $display_value;
}
}
diff --git a/src/Result/ResultInterface.php b/src/Result/ResultInterface.php
index 4ac9d0634d6fddb50e700c510542511d8c6a4dae..658960858e7526984992403b9b9dd5d2da5edec3 100644
--- a/src/Result/ResultInterface.php
+++ b/src/Result/ResultInterface.php
@@ -18,6 +18,7 @@ interface ResultInterface {
* Get the raw value as present in the index.
*
* @return string
+ * The raw value of the result.
*/
public function getRawValue();
@@ -25,6 +26,7 @@ interface ResultInterface {
* Get the display value as present in the index.
*
* @return string
+ * The formatted value of the result.
*/
public function getDisplayValue();
@@ -32,20 +34,23 @@ interface ResultInterface {
* Get the count for the result.
*
* @return mixed
+ * The amount of items for the result.
*/
public function getCount();
/**
- * Get the Url.
+ * Get the url.
*
- * @return Url
+ * @return \Drupal\Core\Url
+ * The url of the search page with the facet url appended.
*/
public function getUrl();
/**
* Set the url.
*
- * @param Url $url
+ * @param \Drupal\Core\Url $url
+ * The url of the search page with the facet url appended.
*/
public function setUrl(Url $url);
@@ -53,6 +58,7 @@ interface ResultInterface {
* Indicate that the value is active (selected).
*
* @param bool $active
+ * A boolean indicating the active state.
*/
public function setActiveState($active);
@@ -60,6 +66,7 @@ interface ResultInterface {
* Returns true if the value is active (selected).
*
* @return bool $active
+ * A boolean indicating the active state.
*/
public function isActive();
@@ -67,7 +74,7 @@ interface ResultInterface {
* Override the display value of a result.
*
* @param string $display_value
- * Override display value
+ * Override display value.
*/
public function setDisplayValue($display_value);
diff --git a/src/Tests/FacetManagerTest.php b/src/Tests/FacetManagerTest.php
index 17769bf5891a7b64b5cceb151cfc105d8fc59082..38b70dff6b6a7f0ae43e1b00c00747dfaddb8a1e 100644
--- a/src/Tests/FacetManagerTest.php
+++ b/src/Tests/FacetManagerTest.php
@@ -24,12 +24,6 @@ class FacetManagerTest extends WebTestBase {
*/
public static $modules = array('facets');
- /**
- * The URL generator.
- *
- * @var \Drupal\Core\Routing\UrlGeneratorInterface
- */
- // Protected $urlGenerator;.
/**
* {@inheritdoc}
*/
@@ -38,7 +32,7 @@ class FacetManagerTest extends WebTestBase {
}
/**
- *
+ * A mocked test, to make sure the test runner doesn't crash.
*/
public function testMock() {
$this->verbose("We need to have at least one test method in a test or otherwise all tests fail.");
diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php
index 2f52e4450210caceb1c0f9f18a520216002f6748..5b33ddc980763da5c7680b5d93756189b9906e29 100644
--- a/src/Tests/IntegrationTest.php
+++ b/src/Tests/IntegrationTest.php
@@ -180,6 +180,7 @@ class IntegrationTest extends FacetWebTestBase {
* Configures empty behavior option to show a text on empty results.
*
* @param string $facet_name
+ * The name of the facet.
*/
protected function setEmptyBehaviorFacetText($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -193,7 +194,7 @@ class IntegrationTest extends FacetWebTestBase {
// Configure the text for empty results behavior.
$edit = [
'facet_settings[empty_behavior]' => 'text',
- 'facet_settings[empty_behavior_container][empty_behavior_text][value]' => 'No results found for this block!'
+ 'facet_settings[empty_behavior_container][empty_behavior_text][value]' => 'No results found for this block!',
];
$this->drupalPostForm(NULL, $edit, $this->t('Save'));
@@ -203,6 +204,7 @@ class IntegrationTest extends FacetWebTestBase {
* Configures a facet to only be visible when accessing to the facet source.
*
* @param string $facet_name
+ * The name of the facet.
*/
protected function setOptionShowOnlyWhenFacetSourceVisible($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -235,7 +237,8 @@ class IntegrationTest extends FacetWebTestBase {
/**
* Tests adding a facet trough the interface.
*
- * @param $facet_name
+ * @param string $facet_name
+ * The name of the facet.
*/
protected function addFacet($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -288,7 +291,8 @@ class IntegrationTest extends FacetWebTestBase {
/**
* Tests editing of a facet through the UI.
*
- * @param $facet_name
+ * @param string $facet_name
+ * The name of the facet.
*/
public function editFacet($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -308,7 +312,6 @@ class IntegrationTest extends FacetWebTestBase {
// the edited facet is shown on the overview page.
$this->assertRaw(t('Facet %name has been updated.', ['%name' => $facet_name . ' - 2']));
-
// Make sure the "-2" suffix is still on the facet when editing a facet.
$this->drupalGet($facet_edit_page);
$this->assertRaw($this->t('Edit facet @facet', ['@facet' => $facet_name . ' - 2']));
@@ -326,6 +329,7 @@ class IntegrationTest extends FacetWebTestBase {
* This deletes an unused facet through the UI.
*
* @param string $facet_name
+ * The name of the facet.
*/
protected function deleteUsedFacet($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -346,6 +350,7 @@ class IntegrationTest extends FacetWebTestBase {
* This deletes a facet through the UI.
*
* @param string $facet_name
+ * The name of the facet.
*/
protected function deleteUnusedFacet($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
@@ -391,11 +396,13 @@ class IntegrationTest extends FacetWebTestBase {
}
/**
- * Covert facet name to machine name.
+ * Convert facet name to machine name.
*
- * @param $facet_name
+ * @param string $facet_name
+ * The name of the facet.
*
* @return string
+ * The facet name changed to a machine name.
*/
protected function convertNameToMachineName($facet_name) {
return preg_replace('@[^a-zA-Z0-9_]+@', '_', strtolower($facet_name));
@@ -405,6 +412,7 @@ class IntegrationTest extends FacetWebTestBase {
* Go to the Delete Facet Page using the facet name.
*
* @param string $facet_name
+ * The name of the facet.
*/
protected function goToDeleteFacetPage($facet_name) {
$facet_id = $this->convertNameToMachineName($facet_name);
diff --git a/src/Tests/WebTestBase.php b/src/Tests/WebTestBase.php
index b9d6e4b3f700f31697929d47f11422e7a22a47f3..703373e40ab308b640d3de5cdeee8bbb9c9d675b 100644
--- a/src/Tests/WebTestBase.php
+++ b/src/Tests/WebTestBase.php
@@ -36,7 +36,15 @@ abstract class WebTestBase extends SimpletestWebTestBase {
*
* @var string[]
*/
- public static $modules = ['views', 'node', 'search_api', 'search_api_test_backend', 'facets', 'search_api_test_views', 'block'];
+ public static $modules = [
+ 'views',
+ 'node',
+ 'search_api',
+ 'search_api_test_backend',
+ 'facets',
+ 'search_api_test_views',
+ 'block',
+ ];
/**
* An admin user used for this test.
@@ -96,16 +104,9 @@ abstract class WebTestBase extends SimpletestWebTestBase {
// Get the URL generator.
$this->urlGenerator = $this->container->get('url_generator');
- // @TODO do we need to create article CT?
- // Create a node article type.
- // $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article']);
- // @TODO do we need to create Page CT?
- // Create a node page type.
- // $this->drupalCreateContentType(['type' => 'page', 'name' => 'Page']);
$this->setUpExampleStructure();
Utility::getIndexTaskManager()->addItemsAll(Index::load($this->indexId));
-
}
/**
@@ -121,7 +122,7 @@ abstract class WebTestBase extends SimpletestWebTestBase {
* (optional) The backend configuration to set for the server.
* @param bool $reset
* (optional) If TRUE, delete the server instead of creating it. (Only the
- * server's ID is required in that case.)
+ * server's ID is required in that case).
*
* @return \Drupal\search_api\ServerInterface
* A search server.
@@ -160,7 +161,7 @@ abstract class WebTestBase extends SimpletestWebTestBase {
* (optional) The ID of a datasource to set for this index.
* @param bool $reset
* (optional) If TRUE, delete the index instead of creating it. (Only the
- * index's ID is required in that case.)
+ * index's ID is required in that case).
*
* @return \Drupal\search_api\IndexInterface
* A search index.
diff --git a/src/Widget/WidgetInterface.php b/src/Widget/WidgetInterface.php
index 500d7f6bc879bb578734234ef2d8bd28e35fba55..536ba71364e41da29b6d676852de137793a74dfb 100644
--- a/src/Widget/WidgetInterface.php
+++ b/src/Widget/WidgetInterface.php
@@ -7,8 +7,9 @@
namespace Drupal\facets\Widget;
use Drupal\facets\FacetInterface;
+
/**
- *
+ * Interface describing the widgets.
*/
interface WidgetInterface {
@@ -16,22 +17,29 @@ interface WidgetInterface {
* Add facet info to the query using the selected query type.
*
* @return mixed
+ * A boolean
*/
public function execute();
/**
* Builds the widget for rendering.
+ *
+ * @param \Drupal\facets\FacetInterface $facet
+ * The facet we need to build.
+ *
+ * @return array
+ * A renderable array.
*/
public function build(FacetInterface $facet);
/**
- * Pick the query type that this widget prefers given an array with
- * query type classes.
+ * Pick the preferred query type for this widget.
*
- * @param $query_types
+ * @param string[] $query_types
* An array keyed with query type name and it's plugin class to load.
*
- * @return mixed
+ * @return string
+ * The query type plugin class to load.
*/
public function getQueryType($query_types);
diff --git a/src/Widget/WidgetPluginManager.php b/src/Widget/WidgetPluginManager.php
index ac8f97b26953ca3890cfb89290dd32b00133dc46..08d22ef3e272768fc7eb05b33271473b382f1f4a 100644
--- a/src/Widget/WidgetPluginManager.php
+++ b/src/Widget/WidgetPluginManager.php
@@ -12,7 +12,7 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
- * Defines a plugin manager for widgets
+ * Defines a plugin manager for widgets.
*/
class WidgetPluginManager extends DefaultPluginManager {
diff --git a/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php b/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
index 966188e1d1a9374d6fceb5c6ff0cf1cbd4a1163b..1c76807ebc1745496cc1002b1026a9655ee652f9 100644
--- a/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
+++ b/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
@@ -1,7 +1,8 @@
setActiveState(TRUE);
$original_results[3]->setActiveState(TRUE);
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$this->processor = new ActiveWidgetOrderProcessor([], 'active_widget_order', []);
}
@@ -58,7 +60,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
$expected_values = [TRUE, TRUE, TRUE, FALSE, FALSE];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->isActive());
@@ -69,7 +71,7 @@ class ActiveWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
$expected_values = array_reverse([TRUE, TRUE, TRUE, FALSE, FALSE]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->isActive());
diff --git a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
index baf5c1db6f43d01894659340ed8bc7f9ef0bdcdb..edf4c270328aa1202d51d5bd712f47f375e3336c 100644
--- a/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class CountLimitProcessorTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -38,7 +40,7 @@ class CountLimitProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -47,7 +49,7 @@ class CountLimitProcessorTest extends UnitTestCase {
$processor_id = 'count_limit';
$this->processor = new CountLimitProcessor([], $processor_id, []);
- $processorDefinitions = [
+ $processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\CountLimitProcessor',
@@ -59,7 +61,7 @@ class CountLimitProcessorTest extends UnitTestCase {
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
- ->willReturn($processorDefinitions);
+ ->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
@@ -75,14 +77,14 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testNoFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 4],
],
]);
$this->processor->setConfiguration(['minimum_items' => 4]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $sorted_results);
@@ -96,7 +98,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testMinEqualsValue() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 5],
@@ -104,7 +106,7 @@ class CountLimitProcessorTest extends UnitTestCase {
]);
$this->processor->setConfiguration(['minimum_items' => 5]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $sorted_results);
@@ -170,7 +172,7 @@ class CountLimitProcessorTest extends UnitTestCase {
*/
public function testFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'count_limit' => [
'settings' => ['minimum_items' => 8],
@@ -178,7 +180,7 @@ class CountLimitProcessorTest extends UnitTestCase {
]);
$this->processor->setConfiguration(['minimum_items' => 8]);
- $sorted_results = $this->processor->build($facet, $this->original_results);
+ $sorted_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(2, $sorted_results);
diff --git a/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
index c9385f73c3cedc2858b3b6c3475d7147fb9f5a60..2fdbebffc45005f718db3b38e22d9fffdb1689f2 100644
--- a/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class CountWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -50,7 +52,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
$this->assertEquals(5, $sorted_results[0]->getCount());
$this->assertEquals('badger', $sorted_results[0]->getDisplayValue());
@@ -65,7 +67,7 @@ class CountWidgetOrderProcessorTest extends UnitTestCase {
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
$this->assertEquals(15, $sorted_results[0]->getCount());
$this->assertEquals('duck', $sorted_results[0]->getDisplayValue());
diff --git a/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
index a865d9b5aa3f76d3e9febe536c329d27b51557f2..dc7790cddb1caf81334835e6b0e5c92d4fe9bbac 100644
--- a/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('thetans', 'thetans', 10),
new Result('xenu', 'xenu', 5),
new Result('Tom', 'Tom', 15),
@@ -53,8 +55,16 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
- $expected_values = ['2', '1977', 'FALSE', 'Hubbard', 'thetans', 'Tom', 'xenu'];
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
+ $expected_values = [
+ '2',
+ '1977',
+ 'FALSE',
+ 'Hubbard',
+ 'thetans',
+ 'Tom',
+ 'xenu',
+ ];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
@@ -64,8 +74,16 @@ class DisplayValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
- $expected_values = array_reverse(['2', '1977', 'FALSE', 'Hubbard', 'thetans', 'Tom', 'xenu']);
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
+ $expected_values = array_reverse([
+ '2',
+ '1977',
+ 'FALSE',
+ 'Hubbard',
+ 'thetans',
+ 'Tom',
+ 'xenu',
+ ]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
diff --git a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
index 2fad7030e4fd18edc23af78a9a130dd682a842a2..07fd5d71d8712df5bd777bd2e52b4c70af717bcb 100644
--- a/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php
@@ -13,6 +13,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
@@ -29,7 +31,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -37,7 +39,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 5),
new Result('duck', 'duck', 15),
@@ -53,7 +55,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
$processor_id = 'exclude_specified_items';
$this->processor = new ExcludeSpecifiedItemsProcessor([], $processor_id, []);
- $processorDefinitions = [
+ $processor_definitions = [
$processor_id => [
'id' => $processor_id,
'class' => 'Drupal\facets\Plugin\facets\processor\ExcludeSpecifiedItemsProcessor',
@@ -65,7 +67,7 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
->getMock();
$manager->expects($this->once())
->method('getDefinitions')
- ->willReturn($processorDefinitions);
+ ->willReturn($processor_definitions);
$manager->expects($this->once())
->method('createInstance')
->willReturn($this->processor);
@@ -80,45 +82,45 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
*/
public function testNoFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => 'alpaca',
- 'regex' => 0
+ 'regex' => 0,
],
],
]);
$this->processor->setConfiguration([
'exclude' => 'alpaca',
- 'regex' => 0
+ 'regex' => 0,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount(count($this->original_results), $filtered_results);
+ $this->assertCount(count($this->originalResults), $filtered_results);
}
/**
- * Test filtering happens for string filter
+ * Test filtering happens for string filter.
*/
public function testStringFilter() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => 'llama',
- 'regex' => 0
+ 'regex' => 0,
],
],
]);
$this->processor->setConfiguration([
'exclude' => 'llama',
- 'regex' => 0
+ 'regex' => 0,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount((count($this->original_results) -1), $filtered_results);
+ $this->assertCount((count($this->originalResults) - 1), $filtered_results);
foreach ($filtered_results as $result) {
$this->assertNotEquals('llama', $result->getDisplayValue());
@@ -126,67 +128,121 @@ class ExcludeSpecifiedItemsProcessorTest extends UnitTestCase {
}
/**
- * Test filtering happens for regex filter
+ * Test filtering happens for regex filter.
*
* @dataProvider provideRegexTests
*/
- public function testRegexFilter($regex, $expectedResults) {
+ public function testRegexFilter($regex, $expected_results) {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setOption('processors', [
'exclude_specified_items' => [
'settings' => [
'exclude' => $regex,
- 'regex' => 1
+ 'regex' => 1,
],
],
]);
$this->processor->setConfiguration([
'exclude' => $regex,
- 'regex' => 1
+ 'regex' => 1,
]);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
- $this->assertCount(count($expectedResults), $filtered_results);
+ $this->assertCount(count($expected_results), $filtered_results);
foreach ($filtered_results as $res) {
- $this->assertTrue(in_array($res->getDisplayValue(), $expectedResults));
+ $this->assertTrue(in_array($res->getDisplayValue(), $expected_results));
}
}
/**
- * Provide multiple data sets for ::testRegexFilter
+ * Provide multiple data sets for ::testRegexFilter.
*/
public function provideRegexTests() {
return [
[
'test',
- ['llama', 'duck', 'badger', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'llama',
- ['badger', 'duck', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'badger',
+ 'duck',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'duck',
- ['llama', 'badger', 'snake', 'snaake', 'snaaake', 'snaaaake', 'snaaaaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaake',
+ 'snaaaake',
+ 'snaaaaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
[
'sn(.*)ke',
- ['llama', 'duck', 'badger']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ ],
],
[
'sn(a*)ke',
- ['llama', 'duck', 'badger', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snbke',
+ ],
],
[
'sn(a+)ke',
- ['llama', 'duck', 'badger', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snbke',
+ ],
],
[
'sn(a{3,5})ke',
- ['llama', 'duck', 'badger', 'snake', 'snaake', 'snaaaaaake', 'snbke']
+ [
+ 'llama',
+ 'duck',
+ 'badger',
+ 'snake',
+ 'snaake',
+ 'snaaaaaake',
+ 'snbke',
+ ],
],
];
}
+
}
diff --git a/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php b/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
index ba9d151dff6b65af9821b359cd522509db942117..4d67c6a78c399e32508c31613d13507aa780e77e 100644
--- a/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php
@@ -13,6 +13,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class HideNonNarrowingResultProcessorTest extends UnitTestCase {
@@ -29,7 +31,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -37,7 +39,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'llama', 10),
new Result('badger', 'badger', 15),
new Result('duck', 'duck', 15),
@@ -53,9 +55,9 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
public function testNoFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
- $filtered_results = $this->processor->build($facet, $this->original_results);
+ $filtered_results = $this->processor->build($facet, $this->originalResults);
$this->assertCount(3, $filtered_results);
@@ -72,7 +74,7 @@ class HideNonNarrowingResultProcessorTest extends UnitTestCase {
*/
public function testFilterResults() {
- $results = $this->original_results;
+ $results = $this->originalResults;
$results[2]->setActiveState(TRUE);
$facet = new Facet([], 'facet');
diff --git a/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php b/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
index a4b22eb4c401eb41832f005cafab3554ccbdc60b..2315ddfef3b0595502f0ae7dd4686788f512525f 100644
--- a/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php
@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class QueryStringUrlProcessorTest extends UnitTestCase {
@@ -32,7 +34,7 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -40,7 +42,7 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('llama', 'Llama', 15),
new Result('badger', 'Badger', 5),
new Result('mushroom', 'Mushroom', 5),
@@ -49,12 +51,15 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
];
}
+ /**
+ * Basic test with one active item.
+ */
public function testSetSingleActiveItem() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setFieldIdentifier('test');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['test:badger']);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -63,12 +68,15 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEquals(['badger'], $facet->getActiveItems());
}
+ /**
+ * Basic test with multiple active items.
+ */
public function testSetMultipleActiveItems() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->setFieldIdentifier('test');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['test:badger', 'test:mushroom', 'donkey:kong']);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -77,11 +85,14 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEquals(['badger', 'mushroom'], $facet->getActiveItems());
}
+ /**
+ * Basic test with an empty build.
+ */
public function testEmptyBuild() {
$facet = new Facet([], 'facet');
$facet->setFacetSourceId('facet_source__dummy');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', []);
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
@@ -89,18 +100,21 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
$this->assertEmpty($results);
}
+ /**
+ * Test with default build.
+ */
public function testBuild() {
$facet = new Facet([], 'facet');
$facet->setFieldIdentifier('test');
$facet->setFacetSourceId('facet_source__dummy');
- $request = new Request;
+ $request = new Request();
$request->query->set('f', []);
$this->setContainer();
$this->processor = new QueryStringUrlProcessor([], 'query_string', [], $request);
- $results = $this->processor->build($facet, $this->original_results);
+ $results = $this->processor->build($facet, $this->originalResults);
/** @var \Drupal\facets\Result\ResultInterface $r */
foreach ($results as $r) {
@@ -109,15 +123,18 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
}
}
+ /**
+ * Test with an active item already from url.
+ */
public function testBuildWithActiveItem() {
$facet = new Facet([], 'facet');
$facet->setFieldIdentifier('test');
$facet->setFacetSourceId('facet_source__dummy');
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[2]->setActiveState(TRUE);
- $request = new Request;
+ $request = new Request();
$request->query->set('f', ['king:kong']);
$this->setContainer();
@@ -137,6 +154,9 @@ class QueryStringUrlProcessorTest extends UnitTestCase {
}
}
+ /**
+ * Set the container for use in unit tests.
+ */
protected function setContainer() {
$router = $this->getMockBuilder('Drupal\Tests\Core\Routing\TestRouterInterface')
->disableOriginalConstructor()
diff --git a/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
index f99a4852c895a87386e407d75cb5279ad3a508f9..16396bb9e1f83b67cc31620b73087cee3db0ef1b 100644
--- a/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class RawValueWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -36,7 +38,7 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
protected function setUp() {
parent::setUp();
- $this->original_results = [
+ $this->originalResults = [
new Result('C', 'thetans', 10),
new Result('B', 'xenu', 5),
new Result('A', 'Tom', 15),
@@ -53,8 +55,16 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting ascending.
*/
public function testAscending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'ASC');
- $expected_values = ['Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977'];
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'ASC');
+ $expected_values = [
+ 'Tom',
+ 'xenu',
+ 'thetans',
+ 'Hubbard',
+ 'FALSE',
+ '2',
+ '1977',
+ ];
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
@@ -64,8 +74,16 @@ class RawValueWidgetOrderProcessorTest extends UnitTestCase {
* Test sorting descending.
*/
public function testDescending() {
- $sorted_results = $this->processor->sortResults($this->original_results, 'DESC');
- $expected_values = array_reverse(['Tom', 'xenu', 'thetans', 'Hubbard', 'FALSE', '2', '1977']);
+ $sorted_results = $this->processor->sortResults($this->originalResults, 'DESC');
+ $expected_values = array_reverse([
+ 'Tom',
+ 'xenu',
+ 'thetans',
+ 'Hubbard',
+ 'FALSE',
+ '2',
+ '1977',
+ ]);
foreach ($expected_values as $index => $value) {
$this->assertEquals($value, $sorted_results[$index]->getDisplayValue());
}
diff --git a/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
index efa31745323d5faa927dce899208147a869710c7..38f371a883ffba1819ed79142d6983d530bacdfa 100644
--- a/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class UidToUserNameCallbackProcessorTest extends UnitTestCase {
@@ -38,7 +40,7 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
/**
- * Test that results were correctly changed
+ * Test that results were correctly changed.
*/
public function testResultsChanged() {
$original_results = [
@@ -69,21 +71,21 @@ class UidToUserNameCallbackProcessorTest extends UnitTestCase {
* Creates and sets up the container to be used in tests.
*/
protected function createMocks() {
- $userStorage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
- $entityManager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
- $entityManager->expects($this->any())
+ $user_storage = $this->getMock('\Drupal\Core\Entity\EntityStorageInterface');
+ $entity_manager = $this->getMock('\Drupal\Core\Entity\EntityManagerInterface');
+ $entity_manager->expects($this->any())
->method('getStorage')
- ->willReturn($userStorage);
+ ->willReturn($user_storage);
$user1 = $this->getMock('\Drupal\Core\Session\AccountInterface');
$user1->method('getDisplayName')
->willReturn('Admin');
- $userStorage->method('load')
+ $user_storage->method('load')
->willReturn($user1);
$container = new ContainerBuilder();
- $container->set('entity.manager', $entityManager);
+ $container->set('entity.manager', $entity_manager);
\Drupal::setContainer($container);
}
diff --git a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
index f49754ced9084e2a58b6d4ae6d3ad32d870dc165..cecd79f0a3d793ee6e55ca5d0f3a241fc115e04f 100644
--- a/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
+++ b/tests/src/Unit/Plugin/query_type/SearchApiStringTest.php
@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\facets\Plugin\query_string\SearchApiStringTest.
*/
-namespace Drupal\Tests\facets\Unit\Plugin\query_string;
+namespace Drupal\Tests\facets\Unit\Plugin\query_type;
use Drupal\facets\Entity\Facet;
use Drupal\facets\Plugin\facets\query_type\SearchApiString;
@@ -13,9 +13,10 @@ use Drupal\search_api\Plugin\views\query\SearchApiQuery;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for query type.
+ *
* @group facets
*/
-
class SearchApiStringTest extends UnitTestCase {
/**
diff --git a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
index 0dfa350114afd400eaf936656bca16f7e91b4cb3..7b3c6c1e817a71b36d5615e592739ccf5cb5617d 100644
--- a/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
+++ b/tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for widget.
+ *
* @group facets
*/
class CheckboxWidgetTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -49,7 +51,7 @@ class CheckboxWidgetTest extends UnitTestCase {
foreach ($original_results as $original_result) {
$original_result->setUrl(new \Drupal\Core\Url('test'));
}
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$link_generator = $this->getMockBuilder('\Drupal\Core\Utility\LinkGenerator')
->disableOriginalConstructor()
@@ -75,7 +77,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*/
public function testDefaultSettings() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$output = $this->widget->build($facet);
@@ -93,7 +95,7 @@ class CheckboxWidgetTest extends UnitTestCase {
*/
public function testShowAmount() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->set('widget_configs', ['show_numbers' => 1]);
$output = $this->widget->build($facet);
diff --git a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
index 5159b648668dbcaef327269beaf77c7a18b2ef99..2f262462c102d59eb99d10837b762979519d7f8e 100644
--- a/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
+++ b/tests/src/Unit/Plugin/widget/LinksWidgetTest.php
@@ -14,6 +14,8 @@ use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
+ * Unit test for widget.
+ *
* @group facets
*/
class LinksWidgetTest extends UnitTestCase {
@@ -30,7 +32,7 @@ class LinksWidgetTest extends UnitTestCase {
*
* @var \Drupal\facets\Result\Result[]
*/
- protected $original_results;
+ protected $originalResults;
/**
* Creates a new processor object for use in the tests.
@@ -49,7 +51,7 @@ class LinksWidgetTest extends UnitTestCase {
foreach ($original_results as $original_result) {
$original_result->setUrl(new \Drupal\Core\Url('test'));
}
- $this->original_results = $original_results;
+ $this->originalResults = $original_results;
$link_generator = $this->getMockBuilder('\Drupal\Core\Utility\LinkGenerator')
->disableOriginalConstructor()
@@ -66,11 +68,11 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testNoFilterResults() {
$facet = new Facet([], 'facet');
- $facet->setResults($this->original_results);
+ $facet->setResults($this->originalResults);
$facet->set('widget_configs', ['show_numbers' => 1]);
$output = $this->widget->build($facet);
@@ -85,10 +87,10 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testHideEmptyCount() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[1] = new Result('badger', 'Badger', 0);
$facet = new Facet([], 'facet');
@@ -107,10 +109,10 @@ class LinksWidgetTest extends UnitTestCase {
}
/**
- * Test widget
+ * Test widget.
*/
public function testActiveItems() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[0]->setActiveState(TRUE);
$original_results[3]->setActiveState(TRUE);
@@ -123,7 +125,12 @@ class LinksWidgetTest extends UnitTestCase {
$this->assertInternalType('array', $output);
$this->assertCount(4, $output['#items']);
- $expected_links = ['(-) Llama (10)', 'Badger (20)', 'Duck (15)', '(-) Alpaca (9)'];
+ $expected_links = [
+ '(-) Llama (10)',
+ 'Badger (20)',
+ 'Duck (15)',
+ '(-) Alpaca (9)',
+ ];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
}
@@ -133,7 +140,7 @@ class LinksWidgetTest extends UnitTestCase {
* Test widget, make sure hiding and showing numbers works.
*/
public function testHideNumbers() {
- $original_results = $this->original_results;
+ $original_results = $this->originalResults;
$original_results[1]->setActiveState(TRUE);
$facet = new Facet([], 'facet');
@@ -159,11 +166,15 @@ class LinksWidgetTest extends UnitTestCase {
$this->assertInternalType('array', $output);
$this->assertCount(4, $output['#items']);
- $expected_links = ['Llama (10)', '(-) Badger (20)', 'Duck (15)', 'Alpaca (9)'];
+ $expected_links = [
+ 'Llama (10)',
+ '(-) Badger (20)',
+ 'Duck (15)',
+ 'Alpaca (9)',
+ ];
foreach ($expected_links as $index => $value) {
$this->assertEquals($value, $output['#items'][$index]);
}
}
}
-
diff --git a/tests/src/Unit/Processor/ProcessorPluginManagerTest.php b/tests/src/Unit/Processor/ProcessorPluginManagerTest.php
index 8669ef9ef8d633e8245fc8eb0ceb6686f0b0f0e4..fcfe48f0dbc185d57ec5366219d8b2c5a0dec0a1 100644
--- a/tests/src/Unit/Processor/ProcessorPluginManagerTest.php
+++ b/tests/src/Unit/Processor/ProcessorPluginManagerTest.php
@@ -1,7 +1,8 @@