Commit 10bc6657 authored by marthinal's avatar marthinal
Browse files

render facet

parent c5e99b31
......@@ -20,6 +20,9 @@ facetapi.facet.*:
field_identifier:
type: string
label: 'Field identifier'
query_type_name:
type: string
label: 'Query Type Name'
widget:
type: string
label: 'Field identifier'
......
......@@ -144,4 +144,6 @@ interface AdapterInterface {
*/
public function build($facet);
public function setResults($facet);
}
......@@ -267,6 +267,8 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
$search_id = $this->searcher_id;
foreach ($this->facets as $facet) {
// Only if the facet is for this query, alter the query.
// @TODO use the line for tests only.
//if ($facet->getName() == 'entity:node/uid' || $facet->getName() == 'entity:node/type') {
if ($facet->getFacetSource() == $search_id) {
// Create the query type plugin.
$query_type_plugin = $this->query_type_plugin_manager->createInstance($facet->getQueryType(),
......@@ -340,15 +342,16 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
$url_processor->processFacet($facet);
}
}
}
public function build($facet) {
// Process the facets.
// @TODO: inject the searcher id on create of the adapter.
$this->searcher_id = $facet->getFacetSource();
// @TODO: Should we update facets each time we build a block?
//$this->processFacets();
$facet = $this->setResults($facet);
$this->processFacets();
// Let the plugin render the facet.
// @TODO: functionality to alter the state of the facet should
......
......@@ -39,6 +39,7 @@ use Drupal\facetapi\Result\ResultInterface;
* "id",
* "name",
* "field_identifier",
* "query_type_name",
* "facet_source",
* "widget",
* "widget_configs",
......@@ -146,6 +147,8 @@ class Facet extends ConfigEntityBase implements FacetInterface {
*/
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
// @TODO Added only for test.
$this->query_type_name = 'search_api_term';
}
/**
......@@ -251,6 +254,8 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->query_type_name;
}
public function getUrlProcessorName() {
return $this->url_processor_name;
}
......
......@@ -97,4 +97,23 @@ class SearchApiViewsAdapter extends AdapterPluginBase {
}
public function setResults($facet) {
$results = $this->searchResultsCache->getResults($this->searcher_id);
$facet_results = $results->getExtraData('search_api_facets');
$configuration = array(
'query' => NULL,
'facet' => $facet,
'results' => $facet_results[$facet->getFieldIdentifier()],
);
// @TODO The query type is not added to the facet.
//$facet->getQueryType()
$query_type_plugin = $this->query_type_plugin_manager->createInstance($facet->getQueryType(),
$configuration
);
return $query_type_plugin->build();
}
}
......@@ -71,5 +71,6 @@ class QueryTypeTerm extends QueryTypePluginBase {
}
$this->facet->setResults($facet_results);
}
return $this->facet;
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class LinksWidget implements WidgetInterface {
$text = '(-) ' . $text;
}
$link_generator = \Drupal::linkGenerator();
$link = $link_generator->generate($text, $result->getUrl());
$link = $text;//$link_generator->generate($text, $result->getUrl());
$items[] = $link;
}
}
......
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