Skip to content
......@@ -8,7 +8,7 @@
<ini name="memory_limit" value="-1"/>
</php>
<testsuites>
<testsuite name="Facetapi Test Suite">
<testsuite name="Facets Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
......
<?php
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiUrlProcessor.
*/
namespace Drupal\facetapi\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API UrlProcessor annotation object.
*
* @see \Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiUrlProcessor extends Plugin {
/**
* The facet_manager plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the url processor plugin.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $label;
/**
* The url processor description.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* Class used to retrieve derivative definitions of the url processor.
*
* @var string
*/
public $derivative = '';
}
......@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiFacet.
* Contains \Drupal\facets\Annotation\FacetsFacetSource.
*/
namespace Drupal\facetapi\Annotation;
namespace Drupal\facets\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API backend annotation object.
* Defines a Facets facet source annotation.
*
* @see \Drupal\facetapi\FacetSource\FacetSourcePluginManager
* @see \Drupal\facetapi\FacetSource\FacetSourceInterface
* @see \Drupal\facetapi\FacetSource\FacetSourcePluginBase
* @see \Drupal\facets\FacetSource\FacetSourcePluginManager
* @see \Drupal\facets\FacetSource\FacetSourcePluginInterface
* @see \Drupal\facets\FacetSource\FacetSourcePluginBase
* @see plugin_api
*
* @Annotation
*/
class FacetApiFacetSource extends Plugin {
class FacetsFacetSource extends Plugin {
/**
* The facet source plugin ID.
......@@ -29,7 +29,7 @@ class FacetApiFacetSource 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
*
......
<?php
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiProcessor.
* Contains \Drupal\facets\Annotation\FacetsProcessor.
*/
namespace Drupal\facetapi\Annotation;
namespace Drupal\facets\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API Processor annotation object.
* Defines a Facets Processor annotation.
*
* @see \Drupal\facetapi\Processor\ProcessorPluginManager
* @see \Drupal\facets\Processor\ProcessorPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiProcessor extends Plugin {
class FacetsProcessor extends Plugin {
/**
* The processor plugin id.
......@@ -58,7 +58,7 @@ class FacetApiProcessor extends Plugin {
* This is represented as an associative array, mapping one or more of the
* stage identifiers to the default weight for that stage. For the available
* stages, see
* \Drupal\facetapi\Processor\ProcessorPluginManager::getProcessingStages().
* \Drupal\facets\Processor\ProcessorPluginManager::getProcessingStages().
*
* @var int[]
*/
......
......@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiQueryType.
* Contains \Drupal\facets\Annotation\FacetsQueryType.
*/
namespace Drupal\facetapi\Annotation;
namespace Drupal\facets\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API QueryType annotation object.
* Defines a Facets query type annotation.
*
* @see \Drupal\facetapi\QueryType\QueryTypePluginManager
* @see \Drupal\facets\QueryType\QueryTypePluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiQueryType extends Plugin {
class FacetsQueryType extends Plugin {
/**
* The query type plugin id.
......
<?php
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiEmptyBehavior.
* Contains \Drupal\facets\Annotation\FacetsUrlProcessor.
*/
namespace Drupal\facetapi\Annotation;
namespace Drupal\facets\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API EmptyBehavior annotation object.
* Defines a Facets URL Processor annotation.
*
* @see \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager
* @see \Drupal\facets\Processor\ProcessorPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiEmptyBehavior extends Plugin {
class FacetsUrlProcessor extends Plugin {
/**
* The empty behavior plugin ID.
* The URL processor plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the empty behavior plugin.
* The human-readable name of the URL processor plugin.
*
* @ingroup plugin_translatable
*
......@@ -38,7 +37,7 @@ class FacetApiEmptyBehavior extends Plugin {
public $label;
/**
* The empty behavior description.
* The URL processor description.
*
* @ingroup plugin_translatable
*
......
......@@ -2,24 +2,24 @@
/**
* @file
* Contains \Drupal\facetapi\Annotation\FacetApiWidget.
* Contains \Drupal\facets\Annotation\FacetsWidget.
*/
namespace Drupal\facetapi\Annotation;
namespace Drupal\facets\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API Widget annotation object.
* Defines a Facets Widget annotation.
*
* @see \Drupal\facetapi\Widget\WidgetPluginManager
* @see \Drupal\facets\Widget\WidgetPluginManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiWidget extends Plugin {
class FacetsWidget extends Plugin {
/**
* The widget plugin id.
......
<?php
/**
* @file
* Contains \Drupal\facetapi\ContextProvider\FacetContextProvider.
*/
namespace Drupal\facetapi\ContextProvider;
use Drupal\Core\Entity\EntityTypeManagerInterface;
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;
protected $facetStorage;
/**
* Create a new instance of the context provider.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->facetStorage = $entity_type_manager->getStorage('facetapi_facet');
}
/**
* {@inheritdoc}
*/
public function getRuntimeContexts(array $unqualified_context_ids = []) {
$ids = $this->facetStorage->getQuery()
->condition('uuid', $unqualified_context_ids, 'IN')
->execute();
$contexts = [];
foreach ($this->facetStorage->loadMultiple($ids) as $facet) {
$context = new Context(new ContextDefinition('entity:facetapi_facet'), $facet);
$contexts[$facet->uuid()] = $context;
}
return $contexts;
}
/**
* {@inheritdoc}
*/
public function getAvailableContexts() {
$facets = $this->facetStorage->loadMultiple();
$contexts = [];
/** @var \Drupal\facetapi\FacetInterface $facet */
foreach ($facets as $facet) {
$context = new Context(
new ContextDefinition('entity:facetapi_facet', $facet->label()),
$facet
);
$contexts[$facet->uuid()] = $context;
}
return $contexts;
}
}
......@@ -2,14 +2,14 @@
/**
* @file
* Contains \Drupal\facetapi\Controller\FacetController.
* Contains \Drupal\facets\Controller\FacetController.
*/
namespace Drupal\facetapi\Controller;
namespace Drupal\facets\Controller;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Controller\ControllerBase;
use Drupal\facetapi\FacetInterface;
use Drupal\facets\FacetInterface;
/**
* Provides route responses for facets.
......@@ -19,7 +19,7 @@ class FacetController extends ControllerBase {
/**
* Displays information about a search facet.
*
* @param \Drupal\facetapi\FacetInterface $facet
* @param \Drupal\facets\FacetInterface $facet
* The facet to display.
*
* @return array
......@@ -29,7 +29,7 @@ class FacetController extends ControllerBase {
// Build the search index information.
$render = array(
'view' => array(
'#theme' => 'facetapi_facet',
'#theme' => 'facets_facet',
'#facet' => $facet,
),
);
......@@ -39,37 +39,32 @@ class FacetController extends ControllerBase {
/**
* Returns a form to add a new facet to a search api index.
*
* @param \Drupal\search_api\IndexInterface $search_api_index
* The search api index this facet will be added to.
*
* @return array
* The facet add form.
*/
public function addForm() {
$facet = \Drupal::service('entity_type.manager')->getStorage('facetapi_facet')->create();
$facet = \Drupal::service('entity_type.manager')->getStorage('facets_facet')->create();
return $this->entityFormBuilder()->getForm($facet, 'default');
}
/**
* Returns a form to edit a facet on a search api index.
*
* @param \Drupal\search_api\IndexInterface $search_api_index
* The search api index this facet will be added to.
* @param \Drupal\facetapi\FacetInterface $facetapi_facet
* Facet currently being edited
* @param \Drupal\facets\FacetInterface $facets_facet
* Facet currently being edited.
*
* @return array
* The facet edit form.
*/
public function editForm(FacetInterface $facetapi_facet) {
$facet = \Drupal::service('entity_type.manager')->getStorage('facetapi_facet')->load($facetapi_facet->id());
public function editForm(FacetInterface $facets_facet) {
$facet = \Drupal::service('entity_type.manager')->getStorage('facets_facet')->load($facets_facet->id());
return $this->entityFormBuilder()->getForm($facet, 'default');
}
/**
* Returns the page title for an facets's "View" tab.
*
* @param \Drupal\facetapi/FacetInterface $facet
* @param \Drupal\facets\FacetInterface $facet
* The facet that is displayed.
*
* @return string
......
<?php
/**
* @file
* Contains \Drupal\facets\Controller\FacetSourceController.
*/
namespace Drupal\facets\Controller;
use Drupal\Core\Controller\ControllerBase;
/**
* Provides route responses for facet source configuration.
*/
class FacetSourceController extends ControllerBase {
/**
* Configuration for the facet source.
*
* @param string $source_id
* The plugin id.
*
* @return array
* A renderable array containing the form.
*/
public function facetSourceConfigForm($source_id) {
// Returns the render array of the FacetSourceConfigForm.
return $this->formBuilder()->getForm('\Drupal\facets\Form\FacetSourceEditForm');
}
}
<?php
/**
* @file
* Contains Drupal\facetap\EmptyBehavior\EmptyBehaviorInterface.
*/
namespace Drupal\facetapi\EmptyBehavior;
use Drupal\Component\Plugin\PluginInspectionInterface;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Specifies the publicly available methods of an empty behavior plugin.
*
* @see \Drupal\facetapi\Annotation\FacetApiEmptyBehavior
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorPluginManager
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorInterface
* @see plugin_api
*/
interface EmptyBehaviorInterface extends PluginInspectionInterface, PluginFormInterface {
/**
* Returns the render array used for the facet that is empty, or has no items.
*
* @param array $facet_empty_behavior_configs
* Configuration for the empty behavior.
*
* @return
* The element's render array.
*/
public function build(array $facet_empty_behavior_configs);
}
<?php
/**
* @file
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginBase.
*/
namespace Drupal\facetapi\EmptyBehavior;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Common base class for empty behavior plugins.
*
* @see \Drupal\facetapi\Annotation\FacetApiEmptyBehavior
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorPluginManager
* @see \Drupal\facetapi\Plugin\EmptyBehavior\EmptyBehaviorInterface
* @see plugin_api
*/
abstract class EmptyBehaviorPluginBase extends PluginBase implements EmptyBehaviorInterface, ContainerFactoryPluginInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Constructs a EmptyBehaviorPluginBase object.
*
* @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 \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
/** @var \Drupal\Core\Config\ConfigFactoryInterface $config_factory */
$config_factory = $container->get('config.factory');
return new static($configuration, $plugin_id, $plugin_definition, $config_factory);
}
/**
* {@inheritdoc}
*/
public function build(array $config) {
return [];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
return FALSE;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {}
}
This diff is collapsed.
<?php
/**
* @file
* Contains \Drupal\facets\Entity\FacetSource.
*/
namespace Drupal\facets\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\facets\FacetSourceInterface;
/**
* Defines the facet source configuration entity.
*
* @ConfigEntityType(
* id = "facets_facet_source",
* label = @Translation("Facet source"),
* handlers = {
* "storage" = "Drupal\Core\Config\Entity\ConfigEntityStorage",
* "list_builder" = "Drupal\facets\FacetListBuilder",
* "form" = {
* "default" = "Drupal\facets\Form\FacetSourceEditForm",
* "edit" = "Drupal\facets\Form\FacetSourceEditForm",
* "display" = "Drupal\facets\Form\FacetSourceDisplayForm",
* "delete" = "Drupal\facets\Form\FacetSourceDeleteConfirmForm",
* },
* },
* admin_permission = "administer facets",
* config_prefix = "facet_source",
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid"
* },
* config_export = {
* "id",
* "name",
* "filter_key",
* "url_processor"
* },
* links = {
* "canonical" = "/admin/config/search/facets/facet-sources/",
* "edit-form" = "/admin/config/search/facets/facet-sources/{facets_facet_source}/edit"
* }
* )
*/
class FacetSource extends ConfigEntityBase implements FacetSourceInterface {
/**
* The ID of the facet source.
*
* @var string
*/
protected $id;
/**
* A name to be displayed for the facet source.
*
* @var string
*/
protected $name;
/**
* The key, used for filters in the query string.
*
* @var string
*/
protected $filter_key;
/**
* The url processor name.
*
* @var string
*/
protected $url_processor = 'query_string';
/**
* {@inheritdoc}
*/
public function getName() {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setFilterKey($filter_key) {
$this->filter_key = $filter_key;
}
/**
* {@inheritdoc}
*/
public function getFilterKey() {
return $this->filter_key;
}
/**
* {@inheritdoc}
*/
public function setUrlProcessor($processor_name) {
$this->url_processor = $processor_name;
}
/**
* {@inheritdoc}
*/
public function getUrlProcessorName() {
return $this->url_processor;
}
}
......@@ -2,12 +2,12 @@
/**
* @file
* Contains \Drupal\facetapi\Exception\Exception.
* Contains \Drupal\facets\Exception\Exception.
*/
namespace Drupal\facetapi\Exception;
namespace Drupal\facets\Exception;
/**
* Represents an exception that occurred in some part of the Facet API.
* Represents an exception that occurred in some part of the Facets.
*/
class Exception extends \Exception {}
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facetapi\Exception\InvalidProcessorException.
* Contains \Drupal\facets\Exception\InvalidProcessorException.
*/
namespace Drupal\facetapi\Exception;
namespace Drupal\facets\Exception;
/**
* Represents an exception that occurred when calling an invalid processor.
......
......@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\facetapi\Exception\InvalidQueryTypeException.
* Contains \Drupal\facets\Exception\InvalidQueryTypeException.
*/
namespace Drupal\facetapi\Exception;
namespace Drupal\facets\Exception;
/**
* Represents an exception that occurred when calling an invalid query type.
......
<?php
/**
* @file
* Contains Drupal\facetapi\FacetInterface.
* Contains Drupal\facets\FacetInterface.
*/
namespace Drupal\facetapi;
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,159 +28,161 @@ interface FacetInterface extends ConfigEntityInterface {
* Returns the facet's widget plugin id.
*
* @return string
* The widget plugin id.
*/
public function getWidget();
/**
* Get field identifier.
* Returns field identifier.
*
* @return string
* The field identifier of this facet.
*/
public function getFieldIdentifier();
/**
* Sets the empty_behavior id.
* Sets field identifier.
*
* @param $behavior_id
* The id for the empty behavior.
* @param string $field_identifier
* The field identifier of this facet.
*
* @return mixed
* @return $this
* Returns self.
*/
public function setFieldEmptyBehavior($behavior_id);
public function setFieldIdentifier($field_identifier);
/**
* Get field empty_behavior.
* Returns the field alias used to identify the facet in the url.
*
* @return mixed
* @return string
* The field alias for the facet.
*/
public function getFieldEmptyBehavior();
public function getFieldAlias();
/**
* Set field identifier.
* Returns the field name of the facet as used in the index.
*
* @return mixed
* @TODO: Check if fieldIdentifier can be used as well!
*
* @return string
* The name of the facet.
*/
public function setFieldIdentifier($field_identifier);
public function getName();
/**
* Get the field alias used to identify the facet in the url.
* Returns the name of the facet for use in the URL.
*
* @return mixed
* @return string
* The name of the facet for use in the URL.
*/
public function getFieldAlias();
public function getUrlAlias();
/**
* Get the field name of the facet as used in the index.
* Sets the name of the facet for use in the URL.
*
* @TODO: Check if fieldIdentifier can be used as well!
*
* @return mixed
* @param string $url_alias
* The name of the facet for use in the URL.
*/
public function getName();
public function setUrlAlias($url_alias);
/**
* Sets an item with value to active.
*
* @param $value
* @param string $value
* An item that is active.
*/
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.
*/
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);
/**
* Get the result for the facet.
* Returns the result for the facet.
*
* @return ResultInterface[] $results
* @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 ResultInterface[] $results
* @param \Drupal\facets\Result\ResultInterface[] $results
* The results of the facet.
*/
public function setResults(array $results);
/**
* Get the query type instance.
* Sets an array of unfiltered results.
*
* @return string
*/
public function getQueryType();
/**
* Get the plugin name for the url processor.
* These unfiltered results are used to set the correct count of the actual
* facet results when using the OR query operator. They are not results value
* objects like those in ::$results.
*
* @return mixed
* @param array $all_results
* Unfiltered results.
*/
public function getUrlProcessorName();
public function setUnfilteredResults(array $all_results = []);
/**
* Retrieves an option.
*
* @param string $name
* The name of an option.
* @param mixed $default
* The value return if the option wasn't set.
* Returns an array of unfiltered results.
*
* @return mixed
* The value of the option.
*
* @see getOptions()
* @return array
* Unfiltered results.
*/
public function getOption($name, $default = NULL);
public function getUnfilteredResults();
/**
* Retrieves an array of all options.
* Returns the query type instance.
*
* @return array
* An associative array of option values, keyed by the option name.
* @return string
* The query type plugin being used.
*/
public function getOptions();
public function getQueryType();
/**
* Sets an option.
*
* @param string $name
* The name of an option.
* @param mixed $option
* The new option.
* Returns the query operator.
*
* @return $this
* @return string
* The query operator being used.
*/
public function setOption($name, $option);
public function getQueryOperator();
/**
* Sets the index's options.
* Returns the value of the exclude boolean.
*
* @param array $options
* The new index options.
* This will return true when the current facet's value should be exclusive
* from the search rather than inclusive.
* When this returns TRUE, the operator will be "<>" instead of "=".
*
* @return $this
* @return bool
* A boolean flag indicating if search should exlude selected facets
*/
public function setOptions(array $options);
public function getExclude();
/**
* Gets the facet manager plugin id.
* Returns the plugin name for the url processor.
*
* @return string
* The id of the url processor.
*/
public function getManagerPluginId();
public function getUrlProcessorName();
/**
* Sets a string representation of the Facet source plugin.
......@@ -185,55 +190,72 @@ interface FacetInterface extends ConfigEntityInterface {
* 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);
/**
* Sets the query operator.
*
* @param string $operator
* The query operator being used.
*/
public function setQueryOperator($operator);
/**
* Sets the exclude.
*
* @param bool $exclude
* A boolean flag indicating if search should exclude selected facets
*/
public function setExclude($exclude);
/**
* Returns the Facet source id.
*
* @return string
* The id of the facet source.
*/
public function getFacetSourceId();
/**
* Returns the plugin instance of a facet source.
*
* @return \Drupal\facetapi\FacetSource\FacetSourceInterface
* @return \Drupal\facets\FacetSource\FacetSourcePluginInterface
* The plugin instance for the facet source.
*/
public function getFacetSource();
/**
* Load the facet sources for this facet.
*
* @param bool|TRUE $only_enabled
* Returns the facet source configuration object.
*
* @return FacetSourceInterface[]
* @return \Drupal\facets\FacetSourceInterface
* A facet source configuration object.
*/
public function getFacetSources($only_enabled = TRUE);
public function getFacetSourceConfig();
/**
* Get the path to which the facet should link.
* Loads the facet sources for this facet.
*
* @param string $path
*/
public function setPath($path);
/**
* Get the path to which the facet should link.
* @param bool|TRUE $only_enabled
* Only return enabled facet sources.
*
* @return NULL|string
* @return \Drupal\facets\FacetSource\FacetSourcePluginInterface[]
* An array of facet sources.
*/
public function getPath();
public function getFacetSources($only_enabled = TRUE);
/**
* Returns an array of processors with their configuration.
*
* @param bool|TRUE $only_enabled
* Only return enabled processors.
*
* @return \Drupal\facetapi\Processor\ProcessorInterface[]
* @return \Drupal\facets\Processor\ProcessorInterface[]
* An array of processors.
*/
public function getProcessors($only_enabled = TRUE);
......@@ -242,18 +264,26 @@ interface FacetInterface extends ConfigEntityInterface {
*
* @param string $stage
* The stage for which to return the processors. One of the
* \Drupal\facetapi\Processor\ProcessorInterface::STAGE_* constants.
* \Drupal\facets\Processor\ProcessorInterface::STAGE_* constants.
* @param bool $only_enabled
* (optional) If FALSE, also include disabled processors. Otherwise, only
* load enabled ones.
*
* @return \Drupal\facetapi\Processor\ProcessorInterface[]
* @return \Drupal\facets\Processor\ProcessorInterface[]
* An array of all enabled (or available, if if $only_enabled is FALSE)
* processors that support the given stage, ordered by the weight for that
* stage.
*/
public function getProcessorsByStage($stage, $only_enabled = TRUE);
/**
* Retrieves this facets's processor configs.
*
* @return array
* An array of processors and their configs.
*/
public function getProcessorConfigs();
/**
* Sets the "only visible when facet source is visible" boolean flag.
*
......@@ -262,14 +292,80 @@ 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();
/**
* Adds a processor for this facet.
*
* @param array $processor
* An array definition for a processor.
*/
public function addProcessor(array $processor);
/**
* Removes a processor for this facet.
*
* @param string $processor_id
* The plugin id of the processor.
*/
public function removeProcessor($processor_id);
/**
* Defines the no-results behavior.
*
* @param array $behavior
* The definition of the behavior.
*/
public function setEmptyBehavior(array $behavior);
/**
* Returns the defined no-results behavior or NULL if none defined.
*
* @return array|NULL
* The behavior definition or NULL.
*/
public function getEmptyBehavior();
/**
* Returns the configuration of the selected widget.
*
* @return array
* The configuration settings for the widget.
*/
public function getWidgetConfigs();
/**
* 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);
/**
* Returns any additional configuration for this facet, not defined above.
*
* @return array
* An array of additional configuration for the facet.
*/
public function getFacetConfigs();
/**
* 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);
}
......@@ -2,15 +2,15 @@
/**
* @file
* Contains \Drupal\facetapi\FacetListBuilder.
* Contains \Drupal\facets\FacetListBuilder.
*/
namespace Drupal\facetapi;
namespace Drupal\facets;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Config\Entity\ConfigEntityListBuilder;
use Drupal\Core\Entity\EntityInterface;
use Drupal\facetapi\FacetSource\FacetSourceInterface;
use Drupal\Core\Link;
/**
* Builds a listing of facet entities.
......@@ -81,7 +81,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
/** @var \Drupal\facets\FacetInterface $entity */
$row = parent::buildRow($entity);
$status_label = $entity->status() ? $this->t('Enabled') : $this->t('Disabled');
......@@ -98,14 +98,14 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'data' => array(
'type' => array(
'data' => 'Facet',
'class' => array('facetapi-type'),
'class' => array('facets-type'),
),
'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(
......@@ -120,14 +120,14 @@ class FacetListBuilder extends ConfigEntityListBuilder {
}
/**
* {@inheritdoc}
* Builds an array of facet sources for display in the overview.
*/
public function buildFacetSourceRow(array $facet_source = []) {
return array(
'data' => array(
'type' => array(
'data' => 'Facet source',
'class' => array('facetapi-type'),
'class' => array('facets-type'),
),
'title' => array(
'data' => $facet_source['id'],
......@@ -135,7 +135,13 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'status' => array(
'data' => '',
),
'operations' => array(),
'operations' => array(
'data' => Link::createFromRoute(
$this->t('Configure'),
'entity.facets_facet_source.edit_form',
['source_id' => $facet_source['id']]
)->toRenderable(),
),
),
'class' => array('facet-source'),
);
......@@ -154,12 +160,12 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'#markup' => $this->t(
'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.'
)
Other modules can also implement a facet source by providing a plugin that implements the FacetSourcePluginInterface.'
),
];
}
$list['#attached']['library'][] = 'facetapi/drupal.facetapi.admin_css';
$list['#attached']['library'][] = 'facets/drupal.facets.admin_css';
$list['#type'] = 'container';
......@@ -169,7 +175,9 @@ class FacetListBuilder extends ConfigEntityListBuilder {
'#rows' => array(),
'#empty' => $groups['lone_facets'] ? '' : $this->t('There are no facet sources or facets defined.'),
'#attributes' => array(
'id' => 'facetapi-groups-list',
'class' => array(
'facets-groups-list',
),
),
);
......@@ -206,7 +214,7 @@ class FacetListBuilder extends ConfigEntityListBuilder {
* - lone_facets: All facets that aren't attached to any facet source.
*/
public function loadGroups() {
$facet_source_plugin_manager = \Drupal::service('plugin.manager.facetapi.facet_source');
$facet_source_plugin_manager = \Drupal::service('plugin.manager.facets.facet_source');
$facets = $this->storage->loadMultiple();
$facet_sources = $facet_source_plugin_manager->getDefinitions();
......@@ -216,11 +224,11 @@ 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) {
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $facet */
/** @var \Drupal\facets\FacetInterface $facet */
if ($facet->getFacetSourceId() == $facet_source['id']) {
$facet_source_groups[$facet_source['id']]['facets'][$facet->id()] = $facet;
// Remove this facet from $facet so it will finally only contain those
......
This diff is collapsed.