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