Commit 56295bbb authored by Jur de Vries's avatar Jur de Vries
Browse files

Development snapshot.

parent 255d8599
......@@ -4,4 +4,7 @@ services:
parent: default_plugin_manager
plugin.manager.facetapi.query_type:
class: Drupal\facetapi\QueryType\QueryTypePluginManager
parent: default_plugin_manager
plugin.manager.facetapi.url_processor:
class: Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager
parent: default_plugin_manager
\ No newline at end of file
......@@ -7,6 +7,7 @@ namespace Drupal\search_api_facets\Plugin\facetapi\adapter;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\facetapi\Adapter\AdapterPluginBase;
use Drupal\facetapi\QueryType\QueryTypePluginManager;
use Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager;
use Drupal\search_api\Query\QueryInterface;
use Drupal\search_api\Query\ResultsCacheInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -41,8 +42,12 @@ class SearchApiViewsAdapter extends AdapterPluginBase {
// @var ResultsCacheInterface
$results_cache = $container->get('search_api.results_static_cache');
// Insert the plugin manager for url processors.
/** @var UrlProcessorPluginManager $url_processor_plugin_manager */
$url_processor_plugin_manager = $container->get('plugin.manager.facetapi.url_processor');
$plugin = new static($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager, $results_cache);
$plugin = new static($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager, $results_cache, $url_processor_plugin_manager);
return $plugin;
......@@ -53,10 +58,11 @@ class SearchApiViewsAdapter extends AdapterPluginBase {
$plugin_id, $plugin_definition,
ModuleHandlerInterface $module_handler,
QueryTypePluginManager $query_type_plugin_manager,
ResultsCacheInterface $results_cache
ResultsCacheInterface $results_cache,
UrlProcessorPluginManager $url_processor_plugin_manager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager);
parent::__construct($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager, $url_processor_plugin_manager);
$this->searchResultsCache = $results_cache;
}
......
......@@ -11,6 +11,8 @@ use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\facetapi\QueryType\QueryTypePluginManager;
use Drupal\facetapi\UrlProcessor\UrlProcessorInterface;
use Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
......@@ -32,6 +34,13 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
*/
protected $query_type_plugin_manager;
/**
* The url processor plugin manager.
*
* @var UrlProcessorPluginManager
*/
protected $url_processor_plugin_manager;
/**
* @var ModuleHandlerInterface
*/
......@@ -76,9 +85,7 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
* @TODO: generalize to ProcessorInterface and properly type hint in __construct().
* The url processor plugin associated with this adapter.
*
* @var FacetapiUrlProcessor
*
* @see FacetapiUrlProcessor
* @var UrlProcessorInterface
*/
protected $urlProcessor;
......@@ -144,6 +151,7 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
* @var string
*/
protected $searcher_id;
/**
* Returns the search path associated with this searcher.
*
......@@ -165,8 +173,11 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
// @var PluginManagerInterface
$query_type_plugin_manager = $container->get('plugin.manager.facetapi.query_type');
// Insert the plugin manager for url processors.
$url_processor_plugin_manager = $container->get('plugin.manager.facetapi.url_processor');
$plugin = new static($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager);
$plugin = new static($configuration, $plugin_id, $plugin_definition, $module_handler, $query_type_plugin_manager, $url_processor_plugin_manager);
return $plugin;
}
......@@ -192,12 +203,14 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
array $configuration,
$plugin_id, $plugin_definition,
ModuleHandlerInterface $module_handler,
QueryTypePluginManager $query_type_plugin_manager
QueryTypePluginManager $query_type_plugin_manager,
UrlProcessorPluginManager $url_processor_plugin_manager
) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->module_handler = $module_handler;
$this->query_type_plugin_manager = $query_type_plugin_manager;
$this->url_processor_plugin_manager = $url_processor_plugin_manager;
}
/**
......@@ -434,7 +447,7 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
* @todo For clarity, should this method be named buildFacets()?
*/
public function processFacets() {
// TODO: Implement processFacets() method.
}
public function build($facet) {
......
<?php
/**
* Contains Drupal\facetapi\AdapterManager
* Contains Drupal\facetapi\Adapter\AdapterManager
*/
namespace Drupal\facetapi\Adapter;
......
<?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 adapter 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
<?php
/**
* @file
* Contains Drupal\facetapi\Facet\FacetInterface
*/
namespace Drupal\facetapi\Facet;
interface FacetInterface {
/**
* Get the field alias used to identify the facet in the url.
*
* @return mixed
*/
public function getFieldAlias();
/**
* Sets an item with value to active.
*
* @param $value
*/
public function setActiveItem($value);
/**
* Get all the active items in the facet.
*
* @return mixed
*/
public function getActiveItems();
}
\ No newline at end of file
......@@ -13,6 +13,7 @@ use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a 'FacetBlock' block.
......
<?php
/**
* @file
* Contains Drupal\facetapi\Plugin\facetapi\url_processor\UrlProcessorQueryString
*/
namespace Drupal\facetapi\Plugin\facetapi\url_processor;
use Drupal\facetapi\Facet\FacetInterface;
use Drupal\facetapi\UrlProcessor\UrlProcessorPluginBase;
/**
* @FacetApiUrlProcessor(
* id = "query_string",
* label = @Translation("Query string url processor"),
* description = @Translation("Most simple url processor which uses the query sting."),
* )
*
* Class UrlProcessorQueryString
* @package Drupal\facetapi\Plugin\facetapi\url_processor
*/
class UrlProcessorQueryString extends UrlProcessorPluginBase{
public function getUri(FacetInterface $facet, $value) {
// TODO: Implement getUri() method.
}
public function processFacet(FacetInterface $facet) {
// TODO: Implement processFacet() method.
}
}
\ No newline at end of file
<?php
/**
* @file
* Contains Drupal\facetapi\UrlProcessor\UrlProcessorInterface
*/
namespace Drupal\facetapi\UrlProcessor;
use Drupal\facetapi\Facet\FacetInterface;
/**
* Interface UrlProcessorInterface
*
* The url processor takes care of retrieving facet information
* from the url, and also handles the generation of facet links.
*
* A facetapi adapter has one url processor.
*
* @package Drupal\facetapi\UrlProcessor
*/
interface UrlProcessorInterface {
/**
* Get the uri for a facet for a value.
*
* The facet knows which values are active or not.
*
* @param FacetInterface $facet
* @param $value
*
* @return mixed
*/
public function getUri(FacetInterface $facet, $value);
/**
* Returns the filter key.
*
* @return string
* A string containing the filter key.
*/
public function getFilterKey();
/**
* Process the facet.
*
* This method sets the active items in a facet.
*
* @param FacetInterface $facet
* @return mixed
*/
public function processFacet(FacetInterface $facet);
}
\ No newline at end of file
<?php
/**
* @file
* Contains Drupal\facetapi\UrlProcessor\UrlProcessorPluginBase
*/
namespace Drupal\facetapi\UrlProcessor;
use Drupal\facetapi\Facet\FacetInterface;
abstract class UrlProcessorPluginBase implements UrlProcessorInterface {
protected $filter_key = 'f';
abstract public function getUri(FacetInterface $facet, $value);
public function getFilterKey() {
return $this->filter_key;
}
abstract public function processFacet(FacetInterface $facet);
}
\ No newline at end of file
<?php
/**
* @file
* Contains Drupal\facetapi\UrlProcessor\UrlProcessorPluginManager
*/
namespace Drupal\facetapi\UrlProcessor;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\DefaultPluginManager;
class UrlProcessorPluginManager extends DefaultPluginManager {
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
parent::__construct('Plugin/facetapi/UrlProcessor', $namespaces, $module_handler, 'Drupal\facetapi\UrlProcessor\UrlProcessorInterface', '\Drupal\facetapi\Annotation\FacetApiUrlProcessor');
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment