Commit 3b0da91b authored by borisson_'s avatar borisson_

Apply all fixes suggested by coder module

parent 7be5fc3b
......@@ -14,10 +14,10 @@
}
#facetapi-groups-list tr.facet-source {
border-top: 1px solid #E6E4DF;
border-top: 1px solid #e6e4df;
}
#facetapi-groups-list tr.facet:last-of-type {
border-bottom: 1px solid #E6E4DF;
border-bottom: 1px solid #e6e4df;
}
#facetapi-groups-list tr.facet-source .facetapi-type,
......
......@@ -10,7 +10,7 @@
*/
/**
* Alter the Facet API Query Type mapping
* Alter the Facet API Query Type mapping.
*
* Modules may implement this hook to alter the mapping that defines how a
* certain data type should be handled in Search API based Facets.
......@@ -25,4 +25,3 @@ function hook_facetapi_search_api_query_type_mapping_alter($backend_plugin_id, a
$query_types['string'] = 'search_api_solr_string';
}
}
......@@ -21,14 +21,14 @@ use Drupal\Component\Annotation\Plugin;
class FacetApiProcessor extends Plugin {
/**
* The processor plugin id
* The processor plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the processor plugin
* The human-readable name of the processor plugin.
*
* @ingroup plugin_translatable
*
......
......@@ -22,14 +22,14 @@ use Drupal\Component\Annotation\Plugin;
class FacetApiQueryType extends Plugin {
/**
* The query type plugin id
* The query type plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the query type plugin
* The human-readable name of the query type plugin.
*
* @ingroup plugin_translatable
*
......
......@@ -21,14 +21,14 @@ use Drupal\Component\Annotation\Plugin;
class FacetApiUrlProcessor extends Plugin {
/**
* The facet_manager plugin id
* The facet_manager plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the url processor plugin
* The human-readable name of the url processor plugin.
*
* @ingroup plugin_translatable
*
......
......@@ -22,14 +22,14 @@ use Drupal\Component\Annotation\Plugin;
class FacetApiWidget extends Plugin {
/**
* The widget plugin id
* The widget plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the widget plugin
* The human-readable name of the widget plugin.
*
* @ingroup plugin_translatable
*
......
......@@ -12,7 +12,9 @@ use Drupal\Core\Plugin\Context\Context;
use Drupal\Core\Plugin\Context\ContextDefinition;
use Drupal\Core\Plugin\Context\ContextProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
*
*/
class FacetContextProvider implements ContextProviderInterface {
use StringTranslationTrait;
......@@ -62,5 +64,4 @@ class FacetContextProvider implements ContextProviderInterface {
return $contexts;
}
}
......@@ -2,7 +2,7 @@
/**
* @file
* Contains Drupal\facetap\EmptyBehavior\EmptyBehaviorInterface
* Contains Drupal\facetap\EmptyBehavior\EmptyBehaviorInterface.
*/
namespace Drupal\facetapi\EmptyBehavior;
......
<?php
/**
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginBase
* @file
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginBase.
*/
namespace Drupal\facetapi\EmptyBehavior;
......@@ -65,7 +66,7 @@ abstract class EmptyBehaviorPluginBase extends PluginBase implements EmptyBehavi
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return false;
return FALSE;
}
/**
......@@ -77,4 +78,5 @@ abstract class EmptyBehaviorPluginBase extends PluginBase implements EmptyBehavi
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {}
}
<?php
/**
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager
* @file
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager.
*/
namespace Drupal\facetapi\EmptyBehavior;
......@@ -17,7 +18,11 @@ use Drupal\Core\Plugin\DefaultPluginManager;
* @see \Drupal\facetapi\EmptyBehavior\EmptyBehaviorInterface
*/
class EmptyBehaviorPluginManager extends DefaultPluginManager {
/**
*
*/
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facetapi/empty_behavior', $namespaces, $module_handler, 'Drupal\facetapi\EmptyBehavior\EmptyBehaviorInterface', 'Drupal\facetapi\Annotation\FacetApiEmptyBehavior');
}
}
......@@ -9,7 +9,6 @@ namespace Drupal\facetapi\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\facetapi\FacetInterface;
use Drupal\facetapi\Result\Result;
/**
* Defines the search index configuration entity.
......@@ -178,7 +177,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
protected $only_visible_when_facet_source_is_visible;
/**
* Widget Plugin Manager
* Widget Plugin Manager.
*
* @var object
*/
......@@ -306,33 +305,54 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this;
}
/**
*
*/
public function getFieldIdentifier() {
return $this->field_identifier;
}
/**
*
*/
public function setFieldIdentifier($field_identifier) {
$this->field_identifier = $field_identifier;
return $this;
}
/**
*
*/
public function getQueryTypes() {
return $this->query_type_name;
}
/**
*
*/
public function setFieldEmptyBehavior($behavior_id) {
$this->empty_behavior = $behavior_id;
return $this;
}
/**
*
*/
public function getFieldEmptyBehavior() {
return $this->empty_behavior;
}
/**
*
*/
public function getUrlProcessorName() {
// @Todo: for now if the url processor is not set, defualt to query_string.
return isset($this->url_processor_name) ? $this->url_processor_name : 'query_string';
}
/**
*
*/
public function getName() {
return $this->name;
}
......@@ -402,6 +422,9 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $parameters;
}
/**
*
*/
public function getResults() {
return $this->results;
}
......@@ -448,7 +471,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
/**
* {@inheritdoc}
*/
public function getFacetSources($only_enabled = false) {
public function getFacetSources($only_enabled = FALSE) {
if (!isset($this->facetSourcePlugins)) {
$this->facetSourcePlugins = [];
......@@ -478,10 +501,16 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return array_intersect_key($this->facetSourcePlugins, array_flip($this->facetSourcePlugins));
}
/**
*
*/
public function setPath($path) {
$this->path = $path;
}
/**
*
*/
public function getPath() {
return $this->path;
}
......
......@@ -10,4 +10,4 @@ namespace Drupal\facetapi\Exception;
/**
* Represents an exception that occurred in some part of the Facet API.
*/
class Exception extends \Exception { }
class Exception extends \Exception {}
......@@ -10,4 +10,4 @@ namespace Drupal\facetapi\Exception;
/**
* Represents an exception that occurred when calling an invalid processor.
*/
class InvalidProcessorException extends \Exception { }
class InvalidProcessorException extends \Exception {}
......@@ -10,4 +10,4 @@ namespace Drupal\facetapi\Exception;
/**
* Represents an exception that occurred when calling an invalid query type.
*/
class InvalidQueryTypeException extends \Exception { }
class InvalidQueryTypeException extends \Exception {}
<?php
/**
* @file
* Contains Drupal\facetapi\FacetInterface
* Contains Drupal\facetapi\FacetInterface.
*/
namespace Drupal\facetapi;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\facetapi\FacetSource\FacetSourceInterface;
use Drupal\facetapi\Result\ResultInterface;
/**
*
*/
interface FacetInterface extends ConfigEntityInterface {
/**
* Sets the facet's widget plugin id.
*
* @param string $widget
*
* @return $this
*/
public function setWidget($widget);
......@@ -91,6 +92,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Check if a value is active.
*
* @param string $value
*
* @return bool
*/
public function isActiveValue($value);
......@@ -171,7 +173,8 @@ interface FacetInterface extends ConfigEntityInterface {
/**
* Gets the facet manager plugin id
* Gets the facet manager plugin id.
*
* @return string
*/
public function getManagerPluginId();
......@@ -182,12 +185,14 @@ interface FacetInterface extends ConfigEntityInterface {
* This is usually the name of the Search-api view.
*
* @param string $facet_source_id
*
* @return $this
*/
public function setFacetSourceId($facet_source_id);
/**
* Returns the Facet source id.
*
* @return string
*/
public function getFacetSourceId();
......@@ -204,6 +209,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Load the facet sources for this facet.
*
* @param bool|TRUE $only_enabled
*
* @return FacetSourceInterface[]
*/
public function getFacetSources($only_enabled = TRUE);
......@@ -226,6 +232,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns an array of processors with their configuration.
*
* @param bool|TRUE $only_enabled
*
* @return \Drupal\facetapi\Processor\ProcessorInterface[]
*/
public function getProcessors($only_enabled = TRUE);
......@@ -250,7 +257,7 @@ interface FacetInterface extends ConfigEntityInterface {
/**
* Sets the "only visible when facet source is visible" boolean flag.
*
* @param boolean $only_visible_when_facet_source_is_visible
* @param bool $only_visible_when_facet_source_is_visible
* A boolean flag indicating if the facet should be hidden on a page that
* does not show the facet source.
*
......@@ -264,4 +271,5 @@ interface FacetInterface extends ConfigEntityInterface {
* @return boolean
*/
public function getOnlyVisibleWhenFacetSourceIsVisible();
}
......@@ -13,7 +13,6 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager;
use Drupal\facetapi\Exception\InvalidProcessorException;
use Drupal\facetapi\FacetInterface;
use Drupal\facetapi\FacetSource\FacetSourceInterface;
use Drupal\facetapi\FacetSource\FacetSourcePluginManager;
use Drupal\facetapi\Processor\BuildProcessorInterface;
use Drupal\facetapi\Processor\PreQueryProcessorInterface;
......@@ -21,7 +20,6 @@ use Drupal\facetapi\Processor\ProcessorInterface;
use Drupal\facetapi\Processor\ProcessorPluginManager;
use Drupal\facetapi\QueryType\QueryTypePluginManager;
use Drupal\facetapi\Widget\WidgetPluginManager;
use \Drupal\facetapi\Entity\Facet;
/**
* Base class for Facet API FacetManagers.
......@@ -303,7 +301,7 @@ class DefaultFacetManager {
// enough to halt all further processing. This should probably go in an
// earlier step of the facet building process but here's fine for now.
$facet_source = $facet->getFacetSource();
if(!$facet_source->isRenderedInCurrentRequest()){
if (!$facet_source->isRenderedInCurrentRequest()) {
return [];
}
}
......@@ -321,9 +319,8 @@ class DefaultFacetManager {
// Get the current results from the facets and let all processors that
// trigger on the build step do their build processing.
// @see \Drupal\facetapi\Processor\BuildProcessorInterface
// @see \Drupal\facetapi\Processor\WidgetOrderProcessorInterface
// @see \Drupal\facetapi\Processor\BuildProcessorInterface.
// @see \Drupal\facetapi\Processor\WidgetOrderProcessorInterface.
$results = $facet->getResults();
foreach ($facet->getProcessors() as $processor) {
......@@ -339,7 +336,6 @@ class DefaultFacetManager {
}
$facet->setResults($results);
// Returns the render array, this render array contains the empty behaviour
// if no results are found. If there are results we're going to initialize
// the widget from the widget plugin manager and return it's build method.
......@@ -375,4 +371,5 @@ class DefaultFacetManager {
$facet->setPath($facet_source_plugin->getPath());
}
}
}
......@@ -12,7 +12,9 @@ use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
......@@ -96,4 +98,5 @@ abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
public function compareDerivatives(array $a, array $b) {
return strnatcasecmp($a['label'], $b['label']);
}
}
......@@ -16,6 +16,7 @@ use Drupal\facetapi\FacetInterface;
* 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.
*
* @see plugin_api
*/
interface FacetSourceInterface {
......@@ -34,6 +35,7 @@ interface FacetSourceInterface {
* Fill in facet data in to the configured facets.
*
* @param \Drupal\facetapi\FacetInterface[] $facets
*
* @return mixed
*/
public function fillFacetsWithResults($facets);
......@@ -49,6 +51,7 @@ interface FacetSourceInterface {
* Get the allowed query types for a given facet for the facet source.
*
* @param \Drupal\facetapi\FacetInterface $facet
*
* @return array of allowed query types
*
* @throws \Drupal\facetapi\Exception\Exception
......@@ -67,7 +70,6 @@ interface FacetSourceInterface {
public function isRenderedInCurrentRequest();
/**
*
* Returns an array of fields that are defined on the datasource.
*
* This returns an array of fields that are defined on the source. This array
......
......@@ -78,7 +78,7 @@ class FacetDeleteConfirmForm extends EntityConfirmFormBase {
*/
protected function isFacetUsedBlock() {
// if the block module is not installed, we should automatically return
// If the block module is not installed, we should automatically return
// false and go ahead with deletion.
if (!\Drupal::moduleHandler()->moduleExists('block')) {
return FALSE;
......
......@@ -15,7 +15,6 @@ use Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager;
use Drupal\facetapi\FacetInterface;
use Drupal\facetapi\Exception\Exception;
use Drupal\facetapi\FacetSource\FacetSourcePluginManager;
use Drupal\facetapi\Processor\ProcessorInterface;
use Drupal\facetapi\Processor\ProcessorPluginManager;
use Drupal\facetapi\Widget\WidgetPluginManager;
use Drupal\views\Views;
......@@ -370,7 +369,7 @@ class FacetForm extends EntityForm {
// @todo Create, use and save SubFormState already here, not only in
// validate(). Also, use proper subset of $form for first parameter?
$config = $this->config('facetapi.facet.' . $facet->id());
if ($config_form = $widget_instance->buildConfigurationForm([], $form_state, ($config instanceof Config) ? $config : null )) {
if ($config_form = $widget_instance->buildConfigurationForm([], $form_state, ($config instanceof Config) ? $config : NULL)) {
$form['widget_configs']['#type'] = 'details';
$form['widget_configs']['#title'] = $this->t('Configure the %widget widget', ['%widget' => $this->getWidgetPluginManager()->getDefinition($widget)['label']]);
$form['widget_configs']['#open'] = $facet->isNew();
......@@ -379,7 +378,7 @@ class FacetForm extends EntityForm {
}
else {
$form['widget_configs']['#type'] = 'container';
$form['widget_configs']['#open'] = true;
$form['widget_configs']['#open'] = TRUE;
$form['widget_configs']['widget_information_dummy'] = [
'#type' => 'hidden',
'#value' => '1',
......@@ -411,7 +410,7 @@ class FacetForm extends EntityForm {
}
else {
$form['empty_behavior_configs']['#type'] = 'container';
$form['empty_behavior_configs']['#open'] = true;
$form['empty_behavior_configs']['#open'] = TRUE;
$form['empty_behavior_configs']['empty_behavior_information_dummy'] = [
'#type' => 'hidden',
'#value' => [],
......
......@@ -12,7 +12,6 @@ namespace Drupal\facetapi\Plugin\Block;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\facetapi\Entity\Facet;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -25,7 +24,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* "facet" = @ContextDefinition("entity:facetapi_facet", label=@Translation("Facet"))
* }
* )
*
*/
class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\facetapi\Plugin\facetapi\empty_behavior\EmptyBehaviorNone
* Contains \Drupal\facetapi\Plugin\facetapi\empty_behavior\EmptyBehaviorNone.
*/
namespace Drupal\facetapi\Plugin\facetapi\empty_behavior;
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\facetapi\Plugin\facetapi\empty_behavior\EmptyBehaviorText
* Contains \Drupal\facetapi\Plugin\facetapi\empty_behavior\EmptyBehaviorText.
*/
namespace Drupal\facetapi\Plugin\facetapi\empty_behavior;
......@@ -50,4 +50,5 @@ class EmptyBehaviorText extends EmptyBehaviorPluginBase {
return $form;
}
}
<?php
/**
* @file
* Contains \Drupal\facetapi\Plugin\facet_api\facet_source\SearchApiBaseFacetSource
* Contains \Drupal\facetapi\Plugin\facet_api\facet_source\SearchApiBaseFacetSource.
*/
namespace Drupal\facetapi\Plugin\facetapi\facet_source;
......@@ -15,7 +15,9 @@ use Drupal\facetapi\FacetSource\FacetSourceInterface;
use Drupal\facetapi\FacetSource\FacetSourcePluginBase;
use Drupal\search_api\FacetApiQueryTypeMappingInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
*
*/
abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
use StringTranslationTrait;
......@@ -71,7 +73,7 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
'#title' => $this->t('Facet field'),
'#description' => $this->t('Choose the indexed field.'),
'#required' => TRUE,
'#default_value' => $facet->getFieldIdentifier()
'#default_value' => $facet->getFieldIdentifier(),
];
return $form;
......@@ -82,7 +84,7 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
*/
public function getFields() {
$indexed_fields = [];
$fields = $this->index->getFields(true);
$fields = $this->index->getFields(TRUE);
foreach ($fields as $field) {
$indexed_fields[$field->getFieldIdentifier()] = $field->getLabel();
}
......@@ -101,7 +103,7 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
// Get the Search API Backend.
$backend = $server->getBackend();
$fields = $this->index->getFields(true);
$fields = $this->index->getFields(TRUE);
foreach ($fields as $field) {
if ($field->getFieldIdentifier() == $field_id) {
return $this->getQueryTypesForDataType($backend, $field->getType());
......@@ -132,7 +134,7 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
public function getQueryTypesForDataType(BackendInterface $backend, $data_type_plugin_id) {
$query_types = [];
// @todo Make this flexible for each data type in Search API.
switch($data_type_plugin_id) {
switch ($data_type_plugin_id) {
case 'boolean':
case 'date':
case 'decimal':
......@@ -144,7 +146,7 @@ abstract class SearchApiBaseFacetSource extends FacetSourcePluginBase {
}
// Find out if the backend implemented the Interface to retrieve specific
// query types for the supported data_types
// query types for the supported data_types.
if ($backend instanceof FacetApiQueryTypeMappingInterface) {
// If the input arrays have the same string keys, then the later value
// for that key will overwrite the previous one. If, however, the arrays
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\facetapi\Plugin\facet_api\facet_source\SearchApiViewsPage
* Contains \Drupal\facetapi\Plugin\facet_api\facet_source\SearchApiViewsPage.
*/
namespace Drupal\facetapi\Plugin\facetapi\facet_source;
......@@ -63,7 +63,7 @@ class SearchApiViewsPage extends SearchApiBaseFacetSource {
// Only add the index if the $query is a Search API Query.
if ($query instanceof SearchApiQuery) {
// Set the Search Api Index
// Set the Search Api Index.
$this->index = $query->getIndex();
}
}
......@@ -103,7 +103,7 @@ class SearchApiViewsPage extends SearchApiBaseFacetSource {
$facet_results = $results->getExtraData('search_api_facets');
// Loop over each facet and execute the build method from the given
// query type
// query type.
foreach ($facets as $facet) {
$configuration = array(
'query' => NULL,
......@@ -133,4 +133,5 @@ class SearchApiViewsPage extends SearchApiBaseFacetSource {
}
return FALSE;
}
}
......@@ -38,13 +38,13 @@ class SearchApiViewsPageDeriver extends FacetSourceDeriverBase {
if($display_info['display_plugin'] == "page"){
$machine_name = $view->id() . PluginBase::DERIVATIVE_SEPARATOR . $name;
$plugin_derivatives[$machine_name] = array(
$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,
) + $base_plugin_definition;
] + $base_plugin_definition;
$sources[] = $this->t('Search api view: ' . $view->label() . ' display: ' . $display_info['display_title']);
}
......
<?php
/**
* @file
*/
namespace Drupal\facetapi\Plugin\facetapi\processor;
......@@ -33,6 +37,9 @@ class ActiveWidgetOrderProcessor extends WidgetOrderPluginBase implements Widget
return $results;
}
/**
*
*/
protected static function sortActiveAsc(Result $a, Result $b) {
if ($a->isActive() == $b->isActive()) {
return 0;
......@@ -40,6 +47,9 @@ class ActiveWidgetOrderProcessor extends WidgetOrderPluginBase implements Widget
return ($a->isActive()) ? -1 : 1;
}
/**
*
*/
protected static function sortActiveDesc(Result $a, Result $b) {
if ($a->isActive() == $b->isActive()) {
return 0;
......
<?php
/**
* @file
*/
namespace Drupal\facetapi\Plugin\facetapi\processor;
......@@ -33,6 +37,9 @@ class CountWidgetOrderProcessor extends WidgetOrderPluginBase implements WidgetO
return $results;
}
/**
*
*/
protected static function sortCountAsc(Result $a, Result $b) {
if ($a->getCount() == $b->getCount()) {
return 0;
......@@ -40,6 +47,9 @@ class CountWidgetOrderProcessor extends WidgetOrderPluginBase implements WidgetO
return ($a->getCount() < $b->getCount()) ? -1 : 1;
}
/**
*
*/
protected static function sortCountDesc(Result $a, Result $b) {
if ($a->getCount() == $b->getCount()) {