Commit 285101ea authored by StryKaizer's avatar StryKaizer

Facets are now not bound to search_api_indexes anymore. UI moved to seperate location

parent bd63e508
......@@ -2,4 +2,4 @@ entity.facetapi_facet.add_form:
route_name: entity.facetapi_facet.add_form
title: 'Add facet'
appears_on:
- entity.search_api_index.facets
- facetapi.overview
facetapi.overview:
title: Facet API
description: 'Configure facets for Search API searchers.'
route_name: facetapi.overview
weight: 30
parent: system.admin_config_search
entity.search_api_server.facets:
route_name: entity.search_api_index.facets
base_route: entity.search_api_index.canonical
title: 'Facets'
weight: 30
......@@ -199,7 +199,7 @@ function facetapi_entity_operation_alter(array &$operations, \Drupal\Core\Entity
$operations['facets'] = array(
'title' => t('Facets'),
'weight' => 40,
'url' => Url::fromRoute('entity.search_api_index.facets', $route_parameters),
'url' => Url::fromRoute('facetapi.overview', $route_parameters),
);
}
}
entity.search_api_index.facets:
path: '/admin/config/search/search-api/index/{search_api_index}/facets'
facetapi.overview:
path: '/admin/config/search/facet-api'
defaults:
_title: 'Facets'
_title: 'Facet API'
_entity_list: 'facetapi_facet'
requirements:
_entity_create_access: 'search_api_index'
entity.facetapi_facet.add_form:
path: '/admin/config/search/search-api/{search_api_index}/facets/add-facet'
path: '/admin/config/search/facet-api/add-facet'
defaults:
_controller: '\Drupal\facetapi\Controller\FacetController::addForm'
_title: 'Add facet'
......@@ -15,7 +15,7 @@ entity.facetapi_facet.add_form:
_entity_create_access: 'facetapi_facet'
entity.facetapi_facet.canonical:
path: '/admin/config/search/search-api/index/{search_api_index}/facets/{facetapi_facet}'
path: '/admin/config/search/facet-api/{facetapi_facet}'
defaults:
_controller: '\Drupal\facetapi\Controller\FacetController::page'
_title_callback: '\Drupal\facetapi\Controller\FacetController::pageTitle'
......@@ -23,7 +23,7 @@ entity.facetapi_facet.canonical:
_entity_access: 'facetapi_facet.view'
entity.facetapi_facet.edit_form:
path: '/admin/config/search/search-api/index/{search_api_index}/facets/{facetapi_facet}/edit'
path: '/admin/config/search/facet-api/{facetapi_facet}/edit'
defaults:
_controller: '\Drupal\facetapi\Controller\FacetController::editForm'
_title: 'Add facet'
......@@ -31,7 +31,7 @@ entity.facetapi_facet.edit_form:
_entity_access: 'facetapi_facet.edit'
entity.facetapi_facet.delete_form:
path: '/admin/config/search/search-api/index/{search_api_index}/facets/{facetapi_facet}/delete'
path: '/admin/config/search/facet-api/{facetapi_facet}/delete'
defaults:
_entity_form: 'facetapi_facet.delete'
requirements:
......
......@@ -46,11 +46,9 @@ class FacetController extends ControllerBase {
* @return array
* The facet add form.
*/
public function addForm(IndexInterface $search_api_index) {
$facet = $this->entityManager()->getStorage('facetapi_facet')->create(array('search_api_index' => $search_api_index->id()));
$form_state_additions = ['search_api_index' => $search_api_index];
return $this->entityFormBuilder()->getForm($facet, 'default', $form_state_additions);
public function addForm() {
$facet = $this->entityManager()->getStorage('facetapi_facet')->create();
return $this->entityFormBuilder()->getForm($facet, 'default');
}
/**
......@@ -64,11 +62,9 @@ class FacetController extends ControllerBase {
* @return array
* The facet edit form.
*/
public function editForm(IndexInterface $search_api_index, FacetInterface $facetapi_facet) {
public function editForm(FacetInterface $facetapi_facet) {
$facet = $this->entityManager()->getStorage('facetapi_facet')->load($facetapi_facet->id());
$form_state_additions = ['search_api_index' => $search_api_index];
return $this->entityFormBuilder()->getForm($facet, 'default', $form_state_additions);
return $this->entityFormBuilder()->getForm($facet, 'default');
}
/**
......
......@@ -44,10 +44,10 @@ use Drupal\facetapi\Result\ResultInterface;
* "widget_configs",
* },
* links = {
* "canonical" = "/admin/config/search/search-api/index/{search_api_index}/facets",
* "add-form" = "/admin/config/search/search-api/index/{search_api_index}/facets/add-facet",
* "edit-form" = "/admin/config/search/search-api/index/{search_api_index}/facets/{facetapi_facet}/edit",
* "delete-form" = "/admin/config/search/search-api/index/{search_api_index}/facets/{facetapi_facet}/delete",
* "canonical" = "/admin/config/search/facet-api",
* "add-form" = "/admin/config/search/facet-api/add-facet",
* "edit-form" = "/admin/config/search/facet-api/{facetapi_facet}/edit",
* "delete-form" = "/admin/config/search/facet-api/{facetapi_facet}/delete",
* }
* )
*/
......@@ -118,13 +118,6 @@ class Facet extends ConfigEntityBase implements FacetInterface {
*/
protected $searcher_name;
/**
* The search api index this facet belongs to.
*
* @var string
*/
protected $search_api_index;
/**
* The plugin name of the url processor.
*
......@@ -264,16 +257,11 @@ class Facet extends ConfigEntityBase implements FacetInterface {
return $this->name;
}
public function getSearchApiIndex() {
return $this->search_api_index;
}
/**
* {@inheritdoc}
*/
protected function urlRouteParameters($rel) {
$parameters = parent::urlRouteParameters($rel);
$parameters['search_api_index'] = $this->getSearchApiIndex();
return $parameters;
}
......
......@@ -27,7 +27,7 @@ class FacetDeleteConfirmForm extends EntityConfirmFormBase {
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('entity.facetapi_facet.canonical', array('facetapi_facet' => $this->entity->id(), 'search_api_index' => $this->entity->getSearchApiIndex()));
return new Url('entity.facetapi_facet.canonical', array('facetapi_facet' => $this->entity->id()));
}
/**
......@@ -43,7 +43,7 @@ class FacetDeleteConfirmForm extends EntityConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('The facet %name has been deleted.', array('%name' => $this->entity->label())));
$form_state->setRedirect('entity.search_api_index.facets', array('search_api_index' => $this->entity->getSearchApiIndex()));
$form_state->setRedirect('facetapi.overview');
}
}
......@@ -14,6 +14,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\facetapi\FacetInterface;
use Drupal\facetapi\FacetApiException;
use Drupal\facetapi\Widget\WidgetPluginManager;
use Drupal\search_api\Entity\Index;
use Drupal\search_api\Form\SubFormState;
use Drupal\search_api\IndexInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -116,10 +117,8 @@ class FacetForm extends EntityForm {
*
* @param \Drupal\facetapi\FacetInterface $facet
* The server that is being created or edited.
* @param \Drupal\search_api\IndexInterface $search_api_index
* The search index we're creating a facet for.
*/
public function buildEntityForm(array &$form, FormStateInterface $form_state, FacetInterface $facet, IndexInterface $search_api_index) {
public function buildEntityForm(array &$form, FormStateInterface $form_state, FacetInterface $facet) {
$form['name'] = array(
'#type' => 'textfield',
......@@ -142,7 +141,7 @@ class FacetForm extends EntityForm {
$form['field_identifier'] = [
'#type' => 'select',
'#options' => $this->getIndexedFields($search_api_index),
'#options' => $this->getIndexedFields(),
'#title' => $this->t('Facet field'),
'#description' => $this->t('Choose the indexed field.'),
'#required' => TRUE,
......@@ -205,15 +204,18 @@ class FacetForm extends EntityForm {
* @return array
* An array of all indexed fields.
*/
protected function getIndexedFields(IndexInterface $search_api_index) {
protected function getIndexedFields() {
$indexed_fields = [];
$search_api_indexes = Index::loadMultiple();
foreach($search_api_indexes as $search_api_index){
foreach ($search_api_index->getDatasources() as $datasource_id => $datasource) {
$fields = $search_api_index->getFieldsByDatasource($datasource_id);
foreach ($fields as $field) {
$indexed_fields[$field->getFieldIdentifier()] = $field->getLabel();
}
}
}
return $indexed_fields;
}
......@@ -295,7 +297,7 @@ class FacetForm extends EntityForm {
$facet = $this->getEntity();
$facet->save();
drupal_set_message($this->t('The facet was successfully saved.'));
$form_state->setRedirect('entity.search_api_index.facets', array('search_api_index' => $facet->getSearchApiIndex()));
$form_state->setRedirect('facetapi.overview');
}
catch (FacetApiException $e) {
$form_state->setRebuild();
......
......@@ -45,7 +45,7 @@ class IntegrationTest extends FacetWebTestBase {
}
protected function addFacet() {
$facet_overview = $this->urlGenerator->generateFromRoute('entity.search_api_index.facets', ['search_api_index' => 'webtest_index']);
$facet_overview = $this->urlGenerator->generateFromRoute('facetapi.overview', ['search_api_index' => 'webtest_index']);
$this->drupalGet($facet_overview);
$this->assertResponse(200);
$this->assertText($this->t('There are no facets defined.'));
......
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