summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoris Vercammen2015-12-05 15:54:39 (GMT)
committerJoris Vercammen2015-12-05 15:54:39 (GMT)
commita23387db94cb0ad4a49d60ef9d9c43d95100b05c (patch)
treea4f5414ae21823e624e4e4832e37271430d0a5db
parentf3d9a9342cb457829e5019e43d59ffbd2cc89c49 (diff)
Fix drupal coding standards
-rw-r--r--core_search_facets/src/FacetsQuery.php9
-rw-r--r--core_search_facets/src/Plugin/CoreSearchFacetSourceInterface.php5
-rw-r--r--core_search_facets/src/Plugin/Search/NodeSearchFacets.php11
-rw-r--r--core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSource.php96
-rw-r--r--core_search_facets/src/Plugin/facets/facet_source/CoreNodeSearchFacetSourceDeriver.php15
-rw-r--r--core_search_facets/src/Plugin/facets/query_type/CoreNodeSearchString.php29
-rw-r--r--css/facets.admin.css2
-rw-r--r--src/ContextProvider/FacetContextProvider.php3
-rw-r--r--src/Controller/FacetController.php4
-rw-r--r--src/Entity/Facet.php47
-rw-r--r--src/FacetInterface.php57
-rw-r--r--src/FacetListBuilder.php15
-rw-r--r--src/FacetManager/DefaultFacetManager.php56
-rw-r--r--src/FacetSource/FacetSourceDeriverBase.php3
-rw-r--r--src/FacetSource/FacetSourceInterface.php17
-rw-r--r--src/FacetSource/FacetSourcePluginBase.php3
-rw-r--r--src/Form/FacetDeleteConfirmForm.php2
-rw-r--r--src/Form/FacetDisplayForm.php132
-rw-r--r--src/Form/FacetForm.php22
-rw-r--r--src/Form/SubFormState.php3
-rw-r--r--src/Plugin/Block/FacetBlock.php18
-rw-r--r--src/Plugin/facets/facet_source/SearchApiBaseFacetSource.php4
-rw-r--r--src/Plugin/facets/facet_source/SearchApiViewsPageDeriver.php12
-rw-r--r--src/Plugin/facets/processor/ActiveWidgetOrderProcessor.php7
-rw-r--r--src/Plugin/facets/processor/CountLimitProcessor.php2
-rw-r--r--src/Plugin/facets/processor/CountWidgetOrderProcessor.php8
-rw-r--r--src/Plugin/facets/processor/DisplayValueWidgetOrderProcessor.php7
-rw-r--r--src/Plugin/facets/processor/ExcludeSpecifiedItemsProcessor.php3
-rw-r--r--src/Plugin/facets/processor/HideNonNarrowingResultProcessor.php10
-rw-r--r--src/Plugin/facets/processor/QueryStringUrlProcessor.php24
-rw-r--r--src/Plugin/facets/processor/RawValueWidgetOrderProcessor.php7
-rw-r--r--src/Plugin/facets/processor/UidToUserNameCallbackProcessor.php3
-rw-r--r--src/Plugin/facets/widget/CheckboxWidget.php10
-rw-r--r--src/Plugin/facets/widget/LinksWidget.php9
-rw-r--r--src/Processor/BuildProcessorInterface.php4
-rw-r--r--src/Processor/PostQueryProcessorInterface.php2
-rw-r--r--src/Processor/PreQueryProcessorInterface.php3
-rw-r--r--src/Processor/ProcessorInterface.php6
-rw-r--r--src/Processor/ProcessorPluginBase.php2
-rw-r--r--src/Processor/UrlProcessorPluginBase.php14
-rw-r--r--src/Processor/WidgetOrderPluginBase.php3
-rw-r--r--src/Processor/WidgetOrderProcessorInterface.php4
-rw-r--r--src/QueryType/QueryTypeInterface.php2
-rw-r--r--src/QueryType/QueryTypePluginBase.php2
-rw-r--r--src/QueryType/QueryTypePluginManager.php2
-rw-r--r--src/Result/Result.php25
-rw-r--r--src/Result/ResultInterface.php15
-rw-r--r--src/Tests/FacetManagerTest.php8
-rw-r--r--src/Tests/IntegrationTest.php20
-rw-r--r--src/Tests/WebTestBase.php21
-rw-r--r--src/Widget/WidgetInterface.php18
-rw-r--r--src/Widget/WidgetPluginManager.php2
-rw-r--r--tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php5
-rw-r--r--tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php10
-rw-r--r--tests/src/Unit/Plugin/processor/CountLimitProcessorTest.php22
-rw-r--r--tests/src/Unit/Plugin/processor/CountWidgetOrderProcessorTest.php10
-rw-r--r--tests/src/Unit/Plugin/processor/DisplayValueWidgetOrderProcessorTest.php30
-rw-r--r--tests/src/Unit/Plugin/processor/ExcludeSpecifiedItemsProcessorTest.php118
-rw-r--r--tests/src/Unit/Plugin/processor/HideNonNarrowingResultProcessorTest.php12
-rw-r--r--tests/src/Unit/Plugin/processor/QueryStringUrlProcessorTest.php42
-rw-r--r--tests/src/Unit/Plugin/processor/RawValueWidgetOrderProcessorTest.php30
-rw-r--r--tests/src/Unit/Plugin/processor/UidToUserNameCallbackProcessorTest.php16
-rw-r--r--tests/src/Unit/Plugin/query_type/SearchApiStringTest.php5
-rw-r--r--tests/src/Unit/Plugin/widget/CheckboxWidgetTest.php10
-rw-r--r--tests/src/Unit/Plugin/widget/LinksWidgetTest.php35
-rw-r--r--tests/src/Unit/Processor/ProcessorPluginManagerTest.php5
-rw-r--r--tests/src/Unit/QueryType/QueryTypePluginManagerTest.php6
67 files changed, 726 insertions, 438 deletions
diff --git a/core_search_facets/src/FacetsQuery.php b/core_search_facets/src/FacetsQuery.php
index 857c861..32f5e9a 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 58e22e3..fa16be5 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 f93ab04..ab5687c 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 d10dd0b..2beb11d 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 5b1c134..f1ba3cd 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 228d240..3cdc1c0 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 503b032..42ae286 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 201906d..c663e5c 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 b1c0abf..de6bb56 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 5c74a7d..3802c96 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 d50426d..7e39f2a 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 2bb0ca4..3469a79 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' => '<div>' . $entity->getFieldAlias() . ' - ' . $entity->getWidget() . '</div>',
- ) + $entity->urlInfo('edit-form')->toRenderArray(),
+ '#type' => 'link',
+ '#title' => $entity->getName(),
+ '#suffix' => '<div>' . $entity->getFieldAlias() . ' - ' . $entity->getWidget() . '</div>',
+ ) + $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.<br />
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 a091001..254ee04 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 f28d32b..3797606 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 20cdb32..aef8c7a 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 a87853e..127b721 100644
--- a/src/FacetSource/FacetSourcePluginBase.php
+++ b/src/FacetSource/FacetSourcePluginBase.php
@@ -1,6 +1,6 @@
<?php
-/**+
+/**
* @file
* Contains \Drupal\facets\FacetSource\FacetSourcePluginBase.
*/
@@ -101,4 +101,5 @@ abstract class FacetSourcePluginBase extends PluginBase implements FacetSourceIn
public function getSearchKeys() {
return $this->keys;
}
+
}
diff --git a/src/Form/FacetDeleteConfirmForm.php b/src/Form/FacetDeleteConfirmForm.php
index 43a1079..134cd2c 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 acee508..d55dfe1 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 2326131..59d8e9a 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 1dbb75b..319e1b5 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 92b17d9..bab4d4b 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 22b53df..b7f86d5 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 e70e4e0..ac85ac5 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 e779e79..2b125c7 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 30c2c1e..284c8a6 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 73cb719..f28f71b 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 4fd4061..638ad73 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 218af40..dd29b4e 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 fcfc478..4c5f99c 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 79cd1ef..1c7bbb5 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 91068ca..f5c9787 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 d160e7d..608138d 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 730a6be..6d8bf49 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 9290ce6..196cd5e 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 221df44..d494f27 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 bf0224f..3a93206 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 840dd2e..72c854d 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 c8ecfe8..6ce9501 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 92788f3..c5221b0 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 7651da8..ee8af0b 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 425d3c8..3014f64 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 d7532a6..e07c84d 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 bb4f761..e4a9ed3 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 fe4010c..497a7f2 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 1b81701..a64fcb1 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 f7e436a..f430981 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 4ac9d06..6589608 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 17769bf..38b70df 100644
--- a/src/Tests/FacetManagerTest.php
+++ b/src/Tests/FacetManagerTest.php
@@ -25,12 +25,6 @@ class FacetManagerTest extends WebTestBase {
public static $modules = array('facets');
/**
- * The URL generator.
- *
- * @var \Drupal\Core\Routing\UrlGeneratorInterface
- */
- // Protected $urlGenerator;.
- /**
* {@inheritdoc}
*/
public function setUp() {
@@ -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 2f52e44..5b33ddc 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 b9d6e4b..703373e 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 500d7f6..536ba71 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 ac8f97b..08d22ef 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 966188e..1c76807 100644
--- a/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
+++ b/tests/src/Unit/FacetSource/FacetSourcePluginManagerTest.php
@@ -1,7 +1,8 @@
<?php
/**
- * @file Contains \Drupal\Tests\facets\Unit\FacetSource\FacetSourcePluginManagerTest.
+ * @file
+ * Contains \Drupal\Tests\facets\Unit\FacetSource\FacetSourcePluginManagerTest.
*/
namespace Drupal\Tests\facets\Unit\FacetSource;
@@ -15,6 +16,8 @@ use Drupal\Tests\UnitTestCase;
use Zend\Stdlib\ArrayObject;
/**
+ * Unit test for plugin manager.
+ *
* @group facets
*/
class FacetSourcePluginManagerTest extends UnitTestCase {
diff --git a/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
index 7684701..81a8e3b 100644
--- a/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
+++ b/tests/src/Unit/Plugin/processor/ActiveWidgetOrderProcessorTest.php
@@ -12,6 +12,8 @@ use Drupal\facets\Result\Result;
use Drupal\Tests\UnitTestCase;
/**
+ * Unit test for processor.
+ *
* @group facets
*/
class ActiveWidgetOrderProcessorTest extends UnitTestCase {
@@ -28,7 +30,7 @@ class ActiveWidgetOrderProcessorTest 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 ActiveWidgetOrderProcessorTest extends UnitTestCase {
$original_results[2]->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 baf5c1d..edf4c27 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 c9385f7..2fdbebf 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 a865d9b..dc7790c 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 2fad703..07fd5d7 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 ba9d151..4d67c6a 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 a4b22eb..2315ddf 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 f99a485..16396bb 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 efa3174..38f371a 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 f49754c..cecd79f 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 0dfa350..7b3c6c1 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 5159b64..2f26246 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 8669ef9..fcfe48f 100644
--- a/tests/src/Unit/Processor/ProcessorPluginManagerTest.php
+++ b/tests/src/Unit/Processor/ProcessorPluginManagerTest.php
@@ -1,7 +1,8 @@
<?php
/**
- * @file Contains \Drupal\Tests\facets\Unit\Processor\ProcessorPluginManagerTest.
+ * @file
+ * Contains \Drupal\Tests\facets\Unit\Processor\ProcessorPluginManagerTest.
*/
namespace Drupal\Tests\facets\Unit\Processor;
@@ -16,6 +17,8 @@ use Drupal\Tests\UnitTestCase;
use Zend\Stdlib\ArrayObject;
/**
+ * Unit test for Processor plugin manager.
+ *
* @group facets
*/
class ProcessorPluginManagerTest extends UnitTestCase {
diff --git a/tests/src/Unit/QueryType/QueryTypePluginManagerTest.php b/tests/src/Unit/QueryType/QueryTypePluginManagerTest.php
index f5b6c68..3650c4b 100644
--- a/tests/src/Unit/QueryType/QueryTypePluginManagerTest.php
+++ b/tests/src/Unit/QueryType/QueryTypePluginManagerTest.php
@@ -1,7 +1,7 @@
<?php
-
/**
- * @file Contains \Drupal\Tests\facets\Unit\QueryType\QueryTypePluginManagerTest.
+ * @file
+ * Contains \Drupal\Tests\facets\Unit\QueryType\QueryTypePluginManagerTest.
*/
namespace Drupal\Tests\facets\Unit\QueryType;
@@ -15,6 +15,8 @@ use Drupal\Tests\UnitTestCase;
use Zend\Stdlib\ArrayObject;
/**
+ * Unit test for the query type plugin manager.
+ *
* @group facets
*/
class QueryTypePluginManagerTest extends UnitTestCase {