diff --git a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php index 182c739..2ec806a 100644 --- a/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php +++ b/core/modules/menu_link_content/src/Form/MenuLinkContentForm.php @@ -104,11 +104,9 @@ public function validateForm(array &$form, FormStateInterface $form_state) { parent::validateForm($form, $form_state); // If the URL is internal, we want to check that the link will resolve in a - // way the user expects. We only check that if the form does not have any - // other errors, because to try to construct a URL from invalid input throws - // an exception, and the user will already be notified from the parent - // validation. - if (!$form_state->hasAnyErrors()) { + // way the user expects. Only check this if the link field is not already + // marked as having an error (for example an invalid link). + if (!$form_state->getError($form['link']['widget'][0]['uri'])) { $link_uri = $form_state->getValue('link')[0]['uri']; $language = $this->language_manager->getLanguage($form_state->getValue('langcode')[0]['value']); $link_url = Url::fromUri($link_uri, [ @@ -116,16 +114,16 @@ public function validateForm(array &$form, FormStateInterface $form_state) { ]); if (!$link_url->isExternal()) { // Find the user input and validate that no URL negotiator will end up - // changing this URL to something else. For example if a user is entering - // a URL with a language prefix. + // changing this URL to something else. For example if a user is + // entering a URL with a language prefix. $user_input = $form_state->getUserInput(); $user_link = $user_input['link'][0]['uri']; // Create a URL object from that. $user_url = $this->pathValidator ->getUrlIfValid($user_link); if ($user_url) { - // If the user entered the special case "" we must allow this to - // not correspond to what Drupal thinks the URL is. + // If the user entered the special case "" we must allow this + // to not correspond to what Drupal thinks the URL is. $user_link = str_replace('', '/', $user_link); // Compare the generated link from what Drupal thinks this is. We want // to do this without language prefixes, if applicable.