Commit a7524691 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2656748 by borisson_: Fix issues with documentation standards

parent 2921f6d6
......@@ -80,8 +80,8 @@ class FacetsQuery extends SearchQuery {
// For complex search queries, add the LIKE conditions.
/*if (!$this->simple) {
$this->join('search_dataset', 'd', 'i.sid = d.sid AND i.type = d.type');
$this->condition($this->conditions);
$this->join('search_dataset', 'd', 'i.sid = d.sid AND i.type = d.type');
$this->condition($this->conditions);
}*/
// Add conditions to query.
......
......@@ -9,15 +9,17 @@ namespace Drupal\core_search_facets\Plugin\Search;
use Drupal\Core\Config\Config;
use Drupal\Core\Database\Driver\mysql\Connection;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\facets\FacetSource\FacetSourcePluginManager;
use Drupal\node\Plugin\Search\NodeSearch;
use Drupal\Core\Render\RendererInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Handles searching for node entities using the Search module index.
......@@ -34,13 +36,13 @@ class NodeSearchFacets extends NodeSearch {
$plugin_id,
$plugin_definition,
Connection $database,
EntityManagerInterface $entity_manager,
EntityTypeManagerInterface $entity_manager,
ModuleHandlerInterface $module_handler,
Config $search_settings,
LanguageManagerInterface $language_manager,
RendererInterface $renderer,
$facet_source_plugin_manager,
$request_stack,
FacetSourcePluginManager $facet_source_plugin_manager,
RequestStack $request_stack,
AccountInterface $account = NULL) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $database, $entity_manager, $module_handler, $search_settings, $language_manager, $renderer, $account);
......@@ -60,7 +62,7 @@ class NodeSearchFacets extends NodeSearch {
$plugin_id,
$plugin_definition,
$container->get('database'),
$container->get('entity.manager'),
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('config.factory')->get('search.settings'),
$container->get('language_manager'),
......@@ -96,6 +98,7 @@ class NodeSearchFacets extends NodeSearch {
'#access' => $this->account && $this->account->hasPermission('use advanced search'),
'#open' => $used_advanced,
);
$form['advanced']['keywords-fieldset'] = array(
'#type' => 'fieldset',
'#title' => t('Keywords'),
......
......@@ -13,10 +13,11 @@ use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface;
use Drupal\facets\FacetInterface;
use Drupal\facets\FacetSource\FacetSourcePluginBase;
use Drupal\facets\FacetSource\FacetSourcePluginInterface;
use Drupal\facets\QueryType\QueryTypePluginManager;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\search\SearchPageInterface;
use Drupal\search\SearchPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
......@@ -54,6 +55,11 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
*/
protected $configFactory;
/**
* The plugin manager for core search plugins.
*
* @var \Drupal\search\SearchPluginManager
*/
protected $searchManager;
/**
......@@ -64,7 +70,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, $query_type_plugin_manager, $search_manager, RequestStack $request_stack) {
public function __construct(array $configuration, $plugin_id, array $plugin_definition, QueryTypePluginManager $query_type_plugin_manager, SearchPluginManager $search_manager, RequestStack $request_stack) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $query_type_plugin_manager);
$this->searchManager = $search_manager;
$this->setSearchKeys($request_stack->getMasterRequest()->query->get('keys'));
......@@ -112,7 +118,6 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
// Get the Facet Specific Query Type so we can process the results
// using the build() function of the query type.
/** @var \Drupal\facets\Entity\Facet $facet **/
$query_type = $this->queryTypePluginManager->createInstance($facet->getQueryType(), $configuration);
$query_type->build();
}
......@@ -143,7 +148,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* @return array
* An array of query types.
*/
public function getQueryTypesForFieldType($field_type) {
protected function getQueryTypesForFieldType($field_type) {
$query_types = [];
switch ($field_type) {
case 'type':
......@@ -204,10 +209,13 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
// Get the current field instances and detect if the field type is allowed.
$fields = FieldConfig::loadMultiple();
/** @var \Drupal\Field\FieldConfigInterface $field */
foreach ($fields as $field) {
// Verify if the target type is allowed for entity reference fields,
// otherwise verify the field type(i.e. integer, float...).
if (in_array($field->getFieldStorageDefinition()->getSetting('target_type'), $allowed_field_types) || in_array($field->getFieldStorageDefinition()->getType(), $allowed_field_types)) {
$target_is_allowed = in_array($field->getFieldStorageDefinition()->getSetting('target_type'), $allowed_field_types);
$field_is_allowed = in_array($field->getFieldStorageDefinition()->getType(), $allowed_field_types);
if ($target_is_allowed || $field_is_allowed) {
/** @var \Drupal\field\Entity\FieldConfig $field */
if (!array_key_exists($field->getName(), $facet_fields)) {
$facet_fields[$field->getName()] = $this->t('@label', ['@label' => $field->getLabel()]);
......@@ -222,6 +230,7 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
* Getter for default node fields.
*
* @return array
* An array containing the default fields enabled on a node.
*/
protected function getDefaultFields() {
return [
......@@ -235,14 +244,14 @@ 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\core_search_facets\FacetsQuery');
$this->facetQueryExtender->join('node_field_data', 'n', 'n.nid = i.sid');
$this->facetQueryExtender
if (!$this->facetQueryExtender) {
$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).
->addTag('node_access')
->searchExpression($this->keys, 'node_search');
}
}
return $this->facetQueryExtender;
}
......@@ -254,10 +263,10 @@ class CoreNodeSearchFacetSource extends FacetSourcePluginBase implements CoreSea
$field_name = $facet->getFieldIdentifier();
$default_fields = $this->getDefaultFields();
if (array_key_exists($facet->getFieldIdentifier(), $default_fields)) {
// 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().
// 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().
// @TODO review if I can refactor this.
$table_alias = $facet->getFieldIdentifier() == 'langcode' ? 'i' : 'n';
$query_info = [
......
......@@ -8,7 +8,9 @@
namespace Drupal\core_search_facets\Plugin\facets\facet_source;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\facets\FacetSource\FacetSourceDeriverBase;
use Drupal\search\SearchPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
......@@ -18,12 +20,24 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
*/
class CoreNodeSearchFacetSourceDeriver extends FacetSourceDeriverBase {
/**
* The plugin manager for core search plugins.
*
* @var \Drupal\search\SearchPluginManager
*/
protected $searchManager;
/**
* Create an instance of the deriver.
* Creates an instance of the deriver.
*
* @param string $base_plugin_id
* The plugin ID.
* @param \Drupal\search\SearchPluginManager $search_manager
* The plugin manager for core search plugins.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
*/
public function __construct(ContainerInterface $container, $base_plugin_id, $search_manager, $entity_type_manager) {
public function __construct($base_plugin_id, SearchPluginManager $search_manager, EntityTypeManagerInterface $entity_type_manager) {
$this->searchManager = $search_manager;
$this->entityTypeManager = $entity_type_manager;
}
......@@ -33,11 +47,10 @@ class CoreNodeSearchFacetSourceDeriver extends FacetSourceDeriverBase {
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static(
$container,
$base_plugin_id,
$container->get('plugin.manager.search'),
$container->get('entity_type.manager')
);
);
}
/**
......
......@@ -21,7 +21,7 @@ use Drupal\facets\Result\Result;
class CoreNodeSearchString extends QueryTypePluginBase {
/**
* Holds the backend's native query object.
* The backend's native query object.
*
* @var \Drupal\search_api\Query\QueryInterface
*/
......@@ -31,7 +31,6 @@ class CoreNodeSearchString extends QueryTypePluginBase {
* {@inheritdoc}
*/
public function execute() {
/** @var \Drupal\core_search_facets\Plugin\CoreSearchFacetSourceInterface $facet_source */
$facet_source = $this->facet->getFacetSource();
$query_info = $facet_source->getQueryInfo($this->facet);
......
......@@ -9,7 +9,6 @@ namespace Drupal\core_search_facets\Tests;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\field_ui\Tests\FieldUiTestTrait;
/**
* Tests integration of hooks.
......@@ -25,7 +24,7 @@ class HooksTest extends WebTestBase {
'node',
'search',
'core_search_facets_test_hooks',
'field'
'field',
];
/**
......@@ -49,7 +48,7 @@ class HooksTest extends WebTestBase {
'field_name' => 'float',
'entity_type' => 'node',
'bundle' => 'page',
'label' => 'Float Field Label'
'label' => 'Float Field Label',
]
)->save();
......@@ -62,7 +61,6 @@ class HooksTest extends WebTestBase {
*/
public function testHooks() {
// Verify that hook_facets_core_allowed_field_types was triggered.
$facet_add_page = 'admin/config/search/facets/add-facet';
$this->drupalGet($facet_add_page);
$this->assertResponse(200);
......
......@@ -35,8 +35,9 @@ class IntegrationTest extends CoreSearchFacetsWebTestBase {
\Drupal::service('plugin.manager.search')->createInstance('node_search')->updateIndex();
search_update_totals();
// Remove the facet blocks each time we run a new test.
unset($this->blocks);
// Make absolutely sure the ::$blocks variable doesn't pass information
// along between tests.
$this->blocks = NULL;
}
/**
......
......@@ -93,10 +93,6 @@ abstract class WebTestBase extends SimpletestWebTestBase {
'administer blocks',
'search content',
]);
$this->unauthorizedUser = $this->drupalCreateUser(['access administration pages']);
$this->anonymousUser = $this->drupalCreateUser();
}
}
......@@ -7,12 +7,10 @@
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\search_api\Query\QueryInterface;
use Drupal\facets\FacetInterface;
/**
* Implements hook_help().
*/
function facets_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the facets module.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\facets\Annotation\FacetsFacet.
* Contains \Drupal\facets\Annotation\FacetsFacetSource.
*/
namespace Drupal\facets\Annotation;
......@@ -29,7 +29,7 @@ class FacetsFacetSource extends Plugin {
public $id;
/**
* The human-readable name of the facet soruce plugin.
* The human-readable name of the facet source plugin.
*
* @ingroup plugin_translatable
*
......
......@@ -167,6 +167,11 @@ class Facet extends ConfigEntityBase implements FacetInterface {
*/
protected $unfiltered_results = [];
/**
* An array of active values.
*
* @var string[]
*/
protected $active_values = [];
/**
......@@ -239,7 +244,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
}
/**
* Gets the widget plugin manager.
* Returns the widget plugin manager.
*
* @return \Drupal\facets\Widget\WidgetPluginManager
* The widget plugin manager.
......@@ -250,13 +255,6 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->widget_plugin_manager ?: $container->get('plugin.manager.facets.widget');
}
/**
* {@inheritdoc}
*/
public function id() {
return $this->id;
}
/**
* {@inheritdoc}
*/
......@@ -320,7 +318,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
\Drupal::logger('facets')
->warning('Processor @id specifies a non-existing @class.', array(
'@id' => $name,
'@class' => $processor_definition['class']
'@class' => $processor_definition['class'],
));
}
}
......@@ -568,7 +566,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
\Drupal::logger('facets')
->warning('Facet Source @id specifies a non-existing @class.', [
'@id' => $name,
'@class' => $facet_source_definition['class']
'@class' => $facet_source_definition['class'],
]);
}
}
......@@ -674,7 +672,7 @@ class Facet extends ConfigEntityBase implements FacetInterface {
/**
* {@inheritdoc}
*/
public function setEmptyBehavior($empty_behavior) {
public function setEmptyBehavior(array $empty_behavior) {
$this->empty_behavior = $empty_behavior;
}
......
......@@ -9,7 +9,6 @@ namespace Drupal\facets\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\facets\FacetSourceInterface;
use Drupal\facets\UrlProcessor\UrlProcessorInterface;
/**
* Defines the facet source configuration entity.
......@@ -76,13 +75,6 @@ class FacetSource extends ConfigEntityBase implements FacetSourceInterface {
*/
protected $url_processor = 'query_string';
/**
* {@inheritdoc}
*/
public function id() {
return $this->id;
}
/**
* {@inheritdoc}
*/
......
......@@ -33,7 +33,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getWidget();
/**
* Get field identifier.
* Returns field identifier.
*
* @return string
* The field identifier of this facet.
......@@ -41,7 +41,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getFieldIdentifier();
/**
* Set field identifier.
* Sets field identifier.
*
* @param string $field_identifier
* The field identifier of this facet.
......@@ -52,7 +52,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function setFieldIdentifier($field_identifier);
/**
* Get the field alias used to identify the facet in the url.
* Returns the field alias used to identify the facet in the url.
*
* @return string
* The field alias for the facet.
......@@ -60,7 +60,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getFieldAlias();
/**
* Get the field name of the facet as used in the index.
* Returns the field name of the facet as used in the index.
*
* @TODO: Check if fieldIdentifier can be used as well!
*
......@@ -70,9 +70,10 @@ interface FacetInterface extends ConfigEntityInterface {
public function getName();
/**
* Gets the name of the facet for use in the URL.
* Returns the name of the facet for use in the URL.
*
* @return string
* The name of the facet for use in the URL.
*/
public function getUrlAlias();
......@@ -80,6 +81,7 @@ interface FacetInterface extends ConfigEntityInterface {
* Sets the name of the facet for use in the URL.
*
* @param string $url_alias
* The name of the facet for use in the URL.
*/
public function setUrlAlias($url_alias);
......@@ -92,7 +94,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function setActiveItem($value);
/**
* Get all the active items in the facet.
* Returns all the active items in the facet.
*
* @return mixed
* An array containing all active items.
......@@ -111,7 +113,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function isActiveValue($value);
/**
* Get the result for the facet.
* Returns the result for the facet.
*
* @return \Drupal\facets\Result\ResultInterface[] $results
* The results of the facet.
......@@ -133,20 +135,21 @@ interface FacetInterface extends ConfigEntityInterface {
* facet results when using the OR query operator. They are not results value
* objects like those in ::$results.
*
* @param array
* @param array $all_results
* Unfiltered results.
*/
public function setUnfilteredResults(array $all_results = []);
/**
* Gets an array of unfiltered results.
* Returns an array of unfiltered results.
*
* @return array
* Unfiltered results.
*/
public function getUnfilteredResults();
/**
* Get the query type instance.
* Returns the query type instance.
*
* @return string
* The query type plugin being used.
......@@ -154,7 +157,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getQueryType();
/**
* Get the query operator.
* Returns the query operator.
*
* @return string
* The query operator being used.
......@@ -162,7 +165,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getQueryOperator();
/**
* Get the plugin name for the url processor.
* Returns the plugin name for the url processor.
*
* @return string
* The id of the url processor.
......@@ -185,7 +188,7 @@ interface FacetInterface extends ConfigEntityInterface {
/**
* Sets the query operator.
*
* @param string
* @param string $operator
* The query operator being used.
*/
public function setQueryOperator($operator);
......@@ -215,7 +218,7 @@ interface FacetInterface extends ConfigEntityInterface {
public function getFacetSourceConfig();
/**
* Load the facet sources for this facet.
* Loads the facet sources for this facet.
*
* @param bool|TRUE $only_enabled
* Only return enabled facet sources.
......@@ -282,60 +285,67 @@ interface FacetInterface extends ConfigEntityInterface {
public function getOnlyVisibleWhenFacetSourceIsVisible();
/**
* Enabled a processor for this facet.
* Adds a processor for this facet.
*
* @param array $processor
* An array definition for a processor.
*/
public function addProcessor(array $processor);
/**
* Disable a processor for this facet.
* Removes a processor for this facet.
*
* @param string $processor_id
* The plugin id of the processor.
*/
public function removeProcessor($processor_id);
/**
* Define the no-results behavior.
* Defines the no-results behavior.
*
* @param array $behavior
* The definition of the behavior.
*/
public function setEmptyBehavior($behavior);
public function setEmptyBehavior(array $behavior);
/**
* Return the defined no-results behavior or NULL if none defined.
* Returns the defined no-results behavior or NULL if none defined.
*
* @return array|NULL
* The behavior definition or NULL.
*/
public function getEmptyBehavior();
/**
* Return the configuration of the selected widget.
* Returns the configuration of the selected widget.
*
* @return array
* The configuration settings for the widget.
*/
public function getWidgetConfigs();
/**
* Set the configuration for the widget of this facet.
* Sets the configuration for the widget of this facet.
*
* @param array $widget_config
* The configuration settings for the widget.
*/
public function setWidgetConfigs(array $widget_config);
/**
* Get any additional configuration for this facet, no defined above.
* Returns any additional configuration for this facet, not defined above.
*
* @return array
* An array of additional configuration for the facet.
*/
public function getFacetConfigs();
/**
* Define any additional configuration for this facet not defined above.
* Defines any additional configuration for this facet not defined above.
*
* @param array $facet_config
* An array of additional configuration for the facet.
*/
public function setFacetConfigs(array $facet_config);
}
......@@ -120,7 +120,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
}
/**
* {@inheritdoc}
* Builds an array of facet sources for display in the overview.
*/
public function buildFacetSourceRow(array $facet_source = []) {
return array(
......
......@@ -108,15 +108,11 @@ class DefaultFacetManager {
protected $facetSourceId;
/**
* Set the search id.
* The entity storage for facets.
*
* @param string $facet_source_id
* The id of the facet source.
* @var \Drupal\Core\Entity\EntityStorageInterface|object
*/
public function setFacetSourceId($facet_source_id) {
$this->facetSourceId = $facet_source_id;
}
protected $facetStorage;
/**
* Constructs a new instance of the DefaultFacetManager.
*
......@@ -136,13 +132,23 @@ class DefaultFacetManager {
$this->widgetPluginManager = $widget_plugin_manager;
$this->facetSourcePluginManager = $facet_source_manager;
$this->processorPluginManager = $processor_plugin_manager;
$this->facet_storage = $entity_type_manager->getStorage('facets_facet');
$this->facetStorage = $entity_type_manager->getStorage('facets_facet');
// Immediately initialize the facets. This can be done directly because the
// only thing needed is the url.
$this->initFacets();
}
/**
* Sets the search id.
*
* @param string $facet_source_id
* The id of the facet source.
*/
public function setFacetSourceId($facet_source_id) {
$this->facetSourceId = $facet_source_id;
}
/**
* Allows the backend to add facet queries to its native query object.
*
......@@ -178,11 +184,11 @@ class DefaultFacetManager {
* An array of enabled facets.
*/
public function getEnabledFacets() {
return $this->facet_storage->loadMultiple();
return $this->facetStorage->loadMultiple();
}
/**
* Get the ID of the facet source.
* Returns the ID of the facet source.
*
* @return string
* The id of the facet source.
......@@ -209,7 +215,7 @@ class DefaultFacetManager {
}
/**
* Initialize enabled facets.
* Initializes enabled facets.
*
* In this method all pre-query processors get called and their contents are
* executed.
......@@ -235,7 +241,7 @@ class DefaultFacetManager {
}
/**
* Build a facet and returns it's render array.
* Builds a facet and returns it as a renderable array.
*
* This method delegates to the relevant plugins to render a facet, it calls
* out to a widget plugin to do the actual rendering when results are found.
......@@ -336,6 +342,7 @@ class DefaultFacetManager {
*
* @param string $facet_id
* The id of the facet.
*
* @return \Drupal\facets\FacetInterface|NULL
* The updated facet if it exists, NULL otherwise.
*/
......
......@@ -82,7 +82,6 @@ abstract class FacetSourceDeriverBase implements ContainerDeriverInterface {
return isset($derivatives[$derivative_id]) ? $derivatives[$derivative_id] : NULL;
}
/**
* Compares two plugin definitions according to their labels.
*
......
......@@ -7,10 +7,8 @@
namespace Drupal\facets\FacetSource;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\facets\Exception\InvalidProcessorException;
use Symfony\Component\DependencyInjection\ContainerInterface;