From c23dde639183eff1ae840c65c64c76ca463b06ba Mon Sep 17 00:00:00 2001 From: David Grayston Date: Tue, 28 Mar 2017 23:06:49 +0100 Subject: [PATCH] Fixing path validation --- src/PathWidgetValidatorTrait.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/PathWidgetValidatorTrait.php b/src/PathWidgetValidatorTrait.php index 27ec90e..1ef9812 100644 --- a/src/PathWidgetValidatorTrait.php +++ b/src/PathWidgetValidatorTrait.php @@ -32,14 +32,16 @@ public static function validateFormElement(array &$element, FormStateInterface $ } } } - else if ($domains = $form_state->getValue(DOMAIN_ACCESS_FIELD)) { + else if ($domain_values = $form_state->getValue(DOMAIN_ACCESS_FIELD)) { // If domains are checked, check existence of alias on each domain. - foreach ($domains as $domain_id) { - // Validate that the submitted alias does not exist yet. - $is_exists = \Drupal::service('path.alias_storage') - ->aliasExistsByDomain($alias, $element['langcode']['#value'], $element['source']['#value'], $domain_id); - if ($is_exists) { - $form_state->setError($element, t('The alias is already in use on :domain.', [':domain' => $domain_id])); + foreach ($domain_values as $domain_value) { + if ($domain = \Drupal::service('domain.loader')->load($domain_value['target_id'])) { + // Validate that the submitted alias does not exist yet. + $is_exists = \Drupal::service('path.alias_storage') + ->aliasExistsByDomain($alias, $element['langcode']['#value'], $element['source']['#value'], $domain->getDomainId()); + if ($is_exists) { + $form_state->setError($element, t('The alias is already in use on :domain.', [':domain' => $domain->get('name')])); + } } } }