/**
* Form element validation handler for matched_path elements.
*
* Note that #maxlength is validated by _form_validate() already.
*
* This checks that the submitted value matches an active route.
*/
public static function validateMatchedPath(&
$element, FormStateInterface
$form_state, &
$complete_form) { if (!
empty($element['#value'
]) && ($element['#validate_path'
] ||
$element['#convert_path'
] != self::CONVERT_NONE
)) { /** @var \Drupal\Core\Url $url */
if ($url = \Drupal::
service('path.validator'
)->
getUrlIfValid($element['#value'
])) { if ($url->
isExternal()) { $form_state->
setError($element,
t('You cannot use an external URL, please enter a relative path.'
));
return;
} if ($element['#convert_path'
] == self::CONVERT_NONE
) { // URL is valid, no conversion required.
return;
} // We do the value conversion here whilst the Url object is in scope
// after validation has occurred.
if ($element['#convert_path'
] == self::CONVERT_ROUTE
) {