Skip to content
services:
plugin.manager.facets.query_type:
class: Drupal\facets\QueryType\QueryTypePluginManager
parent: default_plugin_manager
plugin.manager.facets.widget:
class: Drupal\facets\Widget\WidgetPluginManager
parent: default_plugin_manager
plugin.manager.facets.facet_source:
class: Drupal\facets\FacetSource\FacetSourcePluginManager
parent: default_plugin_manager
plugin.manager.facets.processor:
class: Drupal\facets\Processor\ProcessorPluginManager
arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@string_translation']
plugin.manager.facets.url_processor:
class: Drupal\facets\UrlProcessor\UrlProcessorPluginManager
parent: default_plugin_manager
facets.manager:
class: Drupal\facets\FacetManager\DefaultFacetManager
arguments:
- '@plugin.manager.facets.query_type'
- '@plugin.manager.facets.widget'
- '@plugin.manager.facets.facet_source'
- '@plugin.manager.facets.processor'
- '@entity_type.manager'
/**
* @file
* Attaches show/hide functionality to checkboxes in the "Processor" tab.
*/
(function ($) {
"use strict";
Drupal.behaviors.facetsIndexFormatter = {
attach: function (context, settings) {
$('.search-api-status-wrapper input.form-checkbox', context).each(function () {
var $checkbox = $(this);
var processor_id = $checkbox.data('id');
var $rows = $('.search-api-processor-weight--' + processor_id, context);
var tab = $('.search-api-processor-settings-' + processor_id, context).data('verticalTab');
// Bind a click handler to this checkbox to conditionally show and hide
// the processor's table row and vertical tab pane.
$checkbox.on('click.searchApiUpdate', function () {
if ($checkbox.is(':checked')) {
$rows.show();
if (tab) {
tab.tabShow().updateSummary();
}
}
else {
$rows.hide();
if (tab) {
tab.tabHide().updateSummary();
}
}
});
// Attach summary for configurable items (only for screen-readers).
if (tab) {
tab.details.drupalSetSummary(function () {
return $checkbox.is(':checked') ? Drupal.t('Enabled') : Drupal.t('Disabled');
});
}
// Trigger our bound click handler to update elements to initial state.
$checkbox.triggerHandler('click.searchApiUpdate');
});
}
};
})(jQuery);
......@@ -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\FacetApiFacetManager.
*/
namespace Drupal\facetapi\Annotation;
use Drupal\Component\Annotation\Plugin;
/**
* Defines a Facet API FacetManager annotation object.
*
* @see \Drupal\facetapi\FacetApiFacetManagerManager
* @see plugin_api
*
* @ingroup plugin_api
*
* @Annotation
*/
class FacetApiFacetManager extends Plugin {
/**
* The facet_manager plugin id
*
* @var string
*/
public $id;
/**
* The human-readable name of the facet_manager plugin
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $label;
/**
* The facet_manager description.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* Class used to retrieve derivative definitions of the facet_manager.
*
* @var string
*/
public $derivative = '';
}
<?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 = '';
}
\ No newline at end of file
......@@ -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
* 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
*
......@@ -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,34 +2,34 @@
/**
* @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 facet_manager plugin id
* The query type plugin id.
*
* @var string
*/
public $id;
/**
* The human-readable name of the facet_manager plugin
* The human-readable name of the query type plugin.
*
* @ingroup plugin_translatable
*
......@@ -37,15 +37,6 @@ class FacetApiQueryType extends Plugin {
*/
public $label;
/**
* The facet_manager description.
*
* @ingroup plugin_translatable
*
* @var \Drupal\Core\Annotation\Translation
*/
public $description;
/**
* Class used to retrieve derivative definitions of the facet_manager.
*
......
<?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
*
......@@ -46,4 +45,4 @@ class FacetApiEmptyBehavior extends Plugin {
*/
public $description;
}
\ No newline at end of file
}
......@@ -2,34 +2,34 @@
/**
* @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
* 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
*
......
<?php
/**
* @file
* Contains \Drupal\node\ContextProvider\NodeRouteContext.
*/
namespace Drupal\facetapi\ContextProvider;
use Drupal\Core\Entity\EntityManagerInterface;
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;
public function __construct(EntityManagerInterface $entityManager) {
$this->facetStorage = $entityManager->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 = [];
foreach ($facets as $facet) {
$context = new Context(
new ContextDefinition('entity:facetapi_facet', $facet->label()),
$facet
);
$contexts[$facet->uuid()] = $context;
}
return $contexts;
}
}
......@@ -2,15 +2,14 @@
/**
* @file
* Contains \Drupal\facetapi\Controller\FacetController.
* Contains \Drupal\facets\Controller\FacetController.
*/
namespace Drupal\facetapi\Controller;
namespace Drupal\facets\Controller;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Controller\ControllerBase;
use Drupal\facetapi\FacetInterface;
use Drupal\search_api\IndexInterface;
use Drupal\facets\FacetInterface;
/**
* Provides route responses for facets.
......@@ -20,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
......@@ -30,7 +29,7 @@ class FacetController extends ControllerBase {
// Build the search index information.
$render = array(
'view' => array(
'#theme' => 'facetapi_facet',
'#theme' => 'facets_facet',
'#facet' => $facet,
),
);
......@@ -40,44 +39,39 @@ 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 = $this->entityManager()->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 = $this->entityManager()->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
* The page title.
*/
public function pageTitle(FacetInterface $facet) {
return SafeMarkup::format('@title', array('@title' => $facet->label()));
return new FormattableMarkup('@title', array('@title' => $facet->label()));
}
}
<?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
/**
* 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) {}
}
\ No newline at end of file
<?php
/**
* Contains \Drupal\facetapi\EmptyBehavior\EmptyBehaviorPluginManager
*/
namespace Drupal\facetapi\EmptyBehavior;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
/**
* Provides an EmptyBehavior plugin manager.
*
* @see \Drupal\facetapi\Annotation\FacetApiEmptyBehavior
* @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');
}
}
\ No newline at end of file
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\FacetApiException.
* Contains \Drupal\facets\Exception\Exception.
*/
namespace Drupal\facetapi;
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 FacetApiException extends \Exception { }
class Exception extends \Exception {}
<?php
/**
* @file
* Contains \Drupal\facets\Exception\InvalidProcessorException.
*/
namespace Drupal\facets\Exception;
/**
* Represents an exception that occurred when calling an invalid processor.
*/
class InvalidProcessorException extends \Exception {}