Commit a23387db authored by borisson_'s avatar borisson_

Fix drupal coding standards

parent f3d9a934
......@@ -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])) {
......@@ -120,5 +117,5 @@ class FacetsQuery extends SearchQuery {
public function getSearchExpression() {
return $this->searchExpression;
}
}
}
......@@ -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);
}
......@@ -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')
);
}
......@@ -188,4 +188,3 @@ class NodeSearchFacets extends NodeSearch {
}
}
......@@ -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,7 +220,7 @@ 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
......@@ -228,7 +234,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
],
],
];
//}
// }
/*else {
$query_info = array();
......@@ -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;
}
......
......@@ -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,8 +51,8 @@ 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] = [
......
......@@ -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.
......@@ -52,7 +53,8 @@ class CoreNodeSearchString extends QueryTypePluginBase {
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']);
$this->query->join($join_info['table'], $join_info['alias'],
$join_info['condition']);
}
}*/
......@@ -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 {
}
}
......@@ -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');
......
......@@ -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
......
......@@ -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;
}
......
......@@ -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();
......
......@@ -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.
......@@ -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) {
......
......@@ -32,23 +32,26 @@ class DefaultFacetManager {
use StringTranslationTrait;
/**
* 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;