From a18e2edec705f6164648d450dc588710f0e9cb1c Mon Sep 17 00:00:00 2001
From: Neograph734 <Neograph734@2397482.no-reply.drupal.org>
Date: Tue, 16 Jul 2019 20:59:43 +0200
Subject: [PATCH] Issue #3040947 by borisson_, Neograph734: This alias is
 already in use for another facet defined on the same source

---
 src/Form/FacetForm.php                      | 20 +++++++++++---------
 tests/src/Functional/UrlIntegrationTest.php |  2 +-
 2 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/Form/FacetForm.php b/src/Form/FacetForm.php
index 93cb0f0b..248c2c71 100644
--- a/src/Form/FacetForm.php
+++ b/src/Form/FacetForm.php
@@ -636,14 +636,6 @@ 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.'));
     }
-
-    $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.'));
-      }
-    }
   }
 
   /**
@@ -717,7 +709,17 @@ class FacetForm extends EntityForm {
     $facet->set('show_title', $form_state->getValue(['facet_settings', 'show_title'], FALSE));
 
     $facet->save();
-    \Drupal::messenger()->addMessage($this->t('Facet %name has been updated.', ['%name' => $facet->getName()]));
+
+    $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() === $facet->getUrlAlias() && $other->id() !== $facet->id()) {
+        $this->messenger()->addWarning($this->t('This alias is already in use for another facet defined on the same source.'));
+      }
+    }
+
+    $this->messenger()->addMessage($this->t('Facet %name has been updated.', ['%name' => $facet->getName()]));
   }
 
   /**
diff --git a/tests/src/Functional/UrlIntegrationTest.php b/tests/src/Functional/UrlIntegrationTest.php
index dcdbec0e..e2714a4a 100644
--- a/tests/src/Functional/UrlIntegrationTest.php
+++ b/tests/src/Functional/UrlIntegrationTest.php
@@ -205,7 +205,7 @@ class UrlIntegrationTest extends FacetsTestBase {
   }
 
   /**
-   * Tests that creating a facet with a duplicate url alias is forbidden.
+   * Tests that creating a facet with a duplicate url alias emits a warning.
    */
   public function testCreatingDuplicateUrlAlias() {
     $this->createFacet('Owl', 'owl');
-- 
GitLab