Commit 5e4be677 authored by dcam's avatar dcam Committed by borisson_

Issue #2861541 by dcam, borisson_: Use EntityDeleteForm for entity deletion

parent 2324e66f
...@@ -3,7 +3,7 @@ type: module ...@@ -3,7 +3,7 @@ type: module
description: 'Faceted search interfaces that can be used on Search API searchers.' description: 'Faceted search interfaces that can be used on Search API searchers.'
core: 8.x core: 8.x
package: Search package: Search
configure: facets.overview configure: entity.facets_facet.collection
test_dependencies: test_dependencies:
- search_api:search_api - search_api:search_api
- drupal:views - drupal:views
......
...@@ -2,4 +2,4 @@ entity.facets_facet.add_form: ...@@ -2,4 +2,4 @@ entity.facets_facet.add_form:
route_name: entity.facets_facet.add_form route_name: entity.facets_facet.add_form
title: 'Add facet' title: 'Add facet'
appears_on: appears_on:
- facets.overview - entity.facets_facet.collection
facets.overview: entity.facets_facet.collection:
title: Facets title: Facets
description: 'Create and configure facets and configure existing facet sources.' description: 'Create and configure facets and configure existing facet sources.'
route_name: facets.overview route_name: entity.facets_facet.collection
weight: 30 weight: 30
parent: system.admin_config_search parent: system.admin_config_search
...@@ -30,7 +30,7 @@ function facets_help($route_name, RouteMatchInterface $route_match) { ...@@ -30,7 +30,7 @@ function facets_help($route_name, RouteMatchInterface $route_match) {
$output .= '<p>' . t('Facets test') . '</p>'; $output .= '<p>' . t('Facets test') . '</p>';
return $output; return $output;
case 'facets.overview': case 'entity.facets_facet.collection':
$output = ''; $output = '';
$output .= '<p>' . t('Below is a list of facets grouped by facetsources they are associated with. A facetsource is the instance where the facet does the actual filtering, for example a View on a Search API index.') . '</p>'; $output .= '<p>' . t('Below is a list of facets grouped by facetsources they are associated with. A facetsource is the instance where the facet does the actual filtering, for example a View on a Search API index.') . '</p>';
$output .= '<p>' . t('The facets weight can be changed with drag and drop withing the same facet source. Although you can drag and drop a facet under any facet source, this change will not be performed on save.') . '</p>'; $output .= '<p>' . t('The facets weight can be changed with drag and drop withing the same facet source. Although you can drag and drop a facet under any facet source, this change will not be performed on save.') . '</p>';
......
facets.overview: entity.facets_facet.collection:
path: '/admin/config/search/facets' path: '/admin/config/search/facets'
defaults: defaults:
_title: 'Facets' _title: 'Facets'
......
...@@ -3,7 +3,7 @@ type: module ...@@ -3,7 +3,7 @@ type: module
description: 'Exposes a Facets block summary showing the current search.' description: 'Exposes a Facets block summary showing the current search.'
core: 8.x core: 8.x
package: Search package: Search
configure: facets.overview configure: entity.facets_facet.collection
dependencies: dependencies:
- facets:facets - facets:facets
test_dependencies: test_dependencies:
......
...@@ -2,4 +2,4 @@ entity.facets_summary.add_form: ...@@ -2,4 +2,4 @@ entity.facets_summary.add_form:
route_name: entity.facets_summary.add_form route_name: entity.facets_summary.add_form
title: 'Add facet summary' title: 'Add facet summary'
appears_on: appears_on:
- facets.overview - entity.facets_facet.collection
...@@ -2,50 +2,19 @@ ...@@ -2,50 +2,19 @@
namespace Drupal\facets_summary\Form; namespace Drupal\facets_summary\Form;
use Drupal\Core\Entity\EntityConfirmFormBase; use Drupal\Core\Entity\EntityDeleteForm;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
/** /**
* Defines a confirm form for deleting a facet. * Defines a confirm form for deleting a facet.
*/ */
class FacetsSummaryDeleteConfirmForm extends EntityConfirmFormBase { class FacetsSummaryDeleteConfirmForm extends EntityDeleteForm {
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to delete the facet summary %name?', ['%name' => $this->entity->label()]);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function getCancelUrl() { public function getCancelUrl() {
return new Url('facets.overview'); return new Url('entity.facets_facet.collection');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Delete');
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->entity->delete();
drupal_set_message($this->t('The facet summary %name has been deleted.', ['%name' => $this->entity->label()]));
$form_state->setRedirect('facets.overview');
} }
} }
...@@ -401,4 +401,42 @@ class IntegrationTest extends FacetsTestBase { ...@@ -401,4 +401,42 @@ class IntegrationTest extends FacetsTestBase {
$this->assertSession()->pageTextNotContains(t('Reset facets')); $this->assertSession()->pageTextNotContains(t('Reset facets'));
} }
/**
* Tests for deleting a block.
*/
public function testBlockDelete() {
$name = 'Owl';
$id = 'owl';
$values = [
'name' => $name,
'id' => $id,
'facet_source_id' => 'search_api:views_page__search_api_test_view__page_1',
];
$this->drupalPostForm('admin/config/search/facets/add-facet-summary', $values, 'Save');
$this->drupalPostForm(NULL, [], 'Save');
$block_settings = [
'region' => 'footer',
'id' => $id,
];
$block = $this->drupalPlaceBlock('facets_summary_block:' . $id, $block_settings);
$this->drupalGet('admin/structure/block');
$this->assertSession()->pageTextContains($block->label());
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextContains($name);
// Check for the warning message that additional config entities will be
// deleted if the facet summary is removed.
$this->drupalGet('admin/config/search/facets/facet-summary/' . $id . '/delete');
$this->assertSession()->pageTextContains('The listed configuration will be deleted.');
$this->assertSession()->pageTextContains($block->label());
$this->drupalPostForm(NULL, [], 'Delete');
$this->drupalGet('admin/structure/block/library/classy');
$this->assertSession()->pageTextNotContains($name);
}
} }
...@@ -22,7 +22,7 @@ use Drupal\facets\FacetInterface; ...@@ -22,7 +22,7 @@ use Drupal\facets\FacetInterface;
* "edit" = "Drupal\facets\Form\FacetForm", * "edit" = "Drupal\facets\Form\FacetForm",
* "settings" = "Drupal\facets\Form\FacetSettingsForm", * "settings" = "Drupal\facets\Form\FacetSettingsForm",
* "clone" = "Drupal\facets\Form\FacetCloneForm", * "clone" = "Drupal\facets\Form\FacetCloneForm",
* "delete" = "Drupal\facets\Form\FacetDeleteConfirmForm", * "delete" = "Drupal\Core\Entity\EntityDeleteForm",
* }, * },
* }, * },
* admin_permission = "administer facets", * admin_permission = "administer facets",
...@@ -55,6 +55,7 @@ use Drupal\facets\FacetInterface; ...@@ -55,6 +55,7 @@ use Drupal\facets\FacetInterface;
* "empty_behavior" * "empty_behavior"
* }, * },
* links = { * links = {
* "collection" = "/admin/config/search/facets",
* "add-form" = "/admin/config/search/facets/add-facet", * "add-form" = "/admin/config/search/facets/add-facet",
* "edit-form" = "/admin/config/search/facets/{facets_facet}/edit", * "edit-form" = "/admin/config/search/facets/{facets_facet}/edit",
* "settings-form" = "/admin/config/search/facets/{facets_facet}/settings", * "settings-form" = "/admin/config/search/facets/{facets_facet}/settings",
......
...@@ -149,7 +149,7 @@ class FacetSourceEditForm extends EntityForm { ...@@ -149,7 +149,7 @@ class FacetSourceEditForm extends EntityForm {
parent::submitForm($form, $form_state); parent::submitForm($form, $form_state);
$facet_source = $this->getEntity(); $facet_source = $this->getEntity();
drupal_set_message($this->t('Facet source %name has been saved.', ['%name' => $facet_source->label()])); drupal_set_message($this->t('Facet source %name has been saved.', ['%name' => $facet_source->label()]));
$form_state->setRedirect('facets.overview'); $form_state->setRedirect('entity.facets_facet.collection');
} }
} }
...@@ -170,16 +170,18 @@ class IntegrationTest extends FacetsTestBase { ...@@ -170,16 +170,18 @@ class IntegrationTest extends FacetsTestBase {
$block_id = $block->label(); $block_id = $block->label();
$this->drupalGet('admin/structure/block'); $this->drupalGet('admin/structure/block');
$this->assertText($block_id); $this->assertSession()->pageTextContains($block_id);
$this->drupalGet('admin/structure/block/library/classy'); $this->drupalGet('admin/structure/block/library/classy');
$this->assertText($name); $this->assertSession()->pageTextContains($name);
$this->drupalGet('admin/config/search/facets/' . $id . '/delete'); $this->drupalGet('admin/config/search/facets/' . $id . '/delete');
$this->assertSession()->pageTextContains('The listed configuration will be deleted.');
$this->assertSession()->pageTextContains($block->label());
$this->drupalPostForm(NULL, [], 'Delete'); $this->drupalPostForm(NULL, [], 'Delete');
$this->drupalGet('admin/structure/block/library/classy'); $this->drupalGet('admin/structure/block/library/classy');
$this->assertNoText($name); $this->assertSession()->pageTextNotContains($name);
} }
/** /**
......
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