Commit 1355fe70 authored by borisson_'s avatar borisson_
Browse files

Issue #2581623: Rethink "Searcher" name

parent b49e638a
......@@ -14,9 +14,9 @@ facetapi.facet.*:
status:
type: boolean
label: 'Status'
search_api_index:
facet_source:
type: string
label: 'Search API index'
label: 'Facet source'
field_identifier:
type: string
label: 'Field identifier'
......
......@@ -261,7 +261,7 @@ 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.
if ($facet->getSearcherName() == $search_id) {
if ($facet->getFacetSource() == $search_id) {
// Create the query type plugin.
$query_type_plugin = $this->query_type_plugin_manager->createInstance($facet->getQueryType(),
array('query' => $query, 'facet' => $facet));
......@@ -340,7 +340,7 @@ abstract class AdapterPluginBase extends PluginBase implements AdapterInterface,
public function build($facet) {
// Process the facets.
// @TODO: inject the searcher id on create of the adapter.
$this->searcher_id = $facet->getSearcherName();
$this->searcher_id = $facet->getFacetSource();
$this->processFacets();
// Let the plugin render the facet.
......
......@@ -38,8 +38,8 @@ use Drupal\facetapi\Result\ResultInterface;
* config_export = {
* "id",
* "name",
* "search_api_index",
* "field_identifier",
* "facet_source",
* "widget",
* "widget_configs",
* },
......@@ -112,18 +112,18 @@ class Facet extends ConfigEntityBase implements FacetInterface {
protected $query_type_name;
/**
* The searcher name.
* The plugin name of the url processor.
*
* @var string
*/
protected $searcher_name;
protected $url_processor_name;
/**
* The plugin name of the url processor.
* The name of the facet source.
*
* @var string
*/
protected $url_processor_name;
protected $facet_source;
/**
* The results.
......@@ -245,10 +245,6 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->query_type_name;
}
public function getSearcherName() {
return $this->searcher_name;
}
public function getUrlProcessorName() {
return $this->url_processor_name;
}
......@@ -257,6 +253,21 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->name;
}
/**
* {@inheritdoc}
*/
public function setFacetSource($facet_source) {
$this->facet_source = $facet_source;
return $this;
}
/**
* {@inheritdoc}
*/
public function getFacetSource() {
return $this->facet_source;
}
/**
* {@inheritdoc}
*/
......
......@@ -78,13 +78,6 @@ interface FacetInterface extends ConfigEntityInterface {
*/
public function getQueryType();
/**
* Get the name of the searcher.
*
* @return mixed
*/
public function getSearcherName();
/**
* Get the plugin name for the url processor.
*
......@@ -144,4 +137,20 @@ interface FacetInterface extends ConfigEntityInterface {
*/
public function getAdapterPluginId();
/**
* Sets a string representation of the Facet source plugin.
*
* This is usually the name of the Search-api view.
*
* @param string $facet_source
* @return $this
*/
public function setFacetSource($facet_source);
/**
* Returns the Facet source.
* @return string
*/
public function getFacetSource();
}
......@@ -10,6 +10,7 @@ namespace Drupal\facetapi\Form;
use Drupal\Core\Config\Config;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\facetapi\FacetInterface;
use Drupal\facetapi\FacetApiException;
......@@ -139,6 +140,16 @@ class FacetForm extends EntityForm {
),
);
$facet_sources = $this->getFacetSources();
$form['facet_source'] = [
'#type' => 'select',
'#title' => $this->t('Facet source'),
'#description' => $this->t('Select the source where this facet can find it\'s fields.'),
'#options' => $facet_sources,
'#default_value' => $facet->getFacetSource(),
'#required' => TRUE,
];
$form['field_identifier'] = [
'#type' => 'select',
'#options' => $this->getIndexedFields(),
......@@ -314,4 +325,34 @@ class FacetForm extends EntityForm {
$form_state->setRedirect('entity.facetapi_facet.delete_form', array('facetapi_facet' => $this->getEntity()->id()));
}
/**
* Gets the possible sources for faceted searches.
*
* @return array
*/
protected function getFacetSources() {
$sources = [];
// Gets views that are made on sapi. We have to return an array with keys
// that look like: "search_api_views:search_content:page_1" and values that
// represent a textual representation of that.
/** @var \Drupal\Core\Entity\EntityStorageInterface $viewsStorage */
$viewsStorage = $this->entityManager->getStorage('view');
$allViews = $viewsStorage->loadMultiple();
/** @var \Drupal\views\Entity\View $view */
foreach ($allViews as $view) {
// Hardcoded usage of search api views, for now.
if ($view->get('base_table') == 'search_api_index_default_index') {
$displays = $view->get('display');
foreach ($displays as $name => $display_info) {
$sources['search_api_views' . ':' . $view->id() . ':' . $name] = $this->t('Search api view: ' . $view->label() . ' display: ' . $display_info['display_title']);
}
}
}
return $sources;
}
}
......@@ -79,7 +79,7 @@ class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
/** @var Facet $facet */
$facet = $this->getContextValue('facet');
if (is_null($facet->getSearcherName())) {
if (is_null($facet->getFacetSource())) {
return ['#markup' => "This is why we can't have nice things."];
}
......@@ -89,7 +89,7 @@ class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
/** @var \Drupal\facetapi\Adapter\AdapterInterface $adapter */
$adapter = $this->pluginManager->getMyOwnChangeLaterInstance(
$plugin_id,
$facet->getSearcherName()
$facet->getFacetSource()
);
// Let the adapter build the facets.
......@@ -110,7 +110,7 @@ class FacetBlock extends BlockBase implements ContainerFactoryPluginInterface {
foreach ($facets as $facet_name => $facet) {
$identifier = $facet_name;
$facet_options[$identifier] = $facet->getSearcherName() . ' facet: ' . $facet->getName();
$facet_options[$identifier] = $facet->getFacetSource() . ' facet: ' . $facet->getName();
}
$form['facet_identifier'] = array(
......
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