Commit 99aae5e7 authored by borisson_'s avatar borisson_ Committed by borisson_

Issue #2912030 by borisson_: Validate if url_alias is already used by another...

Issue #2912030 by borisson_: Validate if url_alias is already used by another facet with the same facet source
parent a36a6778
......@@ -606,8 +606,14 @@ class FacetForm extends EntityForm {
elseif (preg_match('/[^a-zA-Z0-9_~\.\-]/', $url_alias)) {
$form_state->setErrorByName('url_alias', $this->t('The URL alias contains characters that are not allowed.'));
}
// @todo: validate if url_alias is already used by another facet with the
// same facet source.
$already_enabled_facets_on_same_source = \Drupal::service('facets.manager')->getFacetsByFacetSourceId($facet->getFacetSourceId());
/** @var \Drupal\facets\FacetInterface $other */
foreach ($already_enabled_facets_on_same_source as $other) {
if ($other->getUrlAlias() === $url_alias && $other->id() !== $facet->id()) {
$form_state->setErrorByName('url_alias', $this->t('This alias is already in use for another facet defined on the same source.'));
}
}
}
/**
......
......@@ -204,4 +204,15 @@ class UrlIntegrationTest extends FacetsTestBase {
}
}
/**
* Tests that creating a facet with a duplicate url alias is forbidden.
*/
public function testCreatingDuplicateUrlAlias() {
$this->createFacet('Owl', 'owl');
$this->createFacet('Another owl', 'another_owl');
$this->drupalGet('admin/config/search/facets/another_owl/edit');
$this->drupalPostForm(NULL, ['facet_settings[url_alias]' => 'owl'], 'Save');
$this->assertSession()->pageTextContains('This alias is already in use for another facet defined on the same source.');
}
}
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