public function LoginDestinationRuleForm::validateUriElement in Login Destination 8.2
Same name and namespace in other branches
- 8 src/Form/LoginDestinationRuleForm.php \Drupal\login_destination\Form\LoginDestinationRuleForm::validateUriElement()
Form element validation handler for the 'uri' element.
Disallows saving inaccessible or untrusted URLs.
See also
LinkWidget::validateUriElement()
File
- src/
Form/ LoginDestinationRuleForm.php, line 223
Class
- LoginDestinationRuleForm
- Base for controller for login destination add/edit forms.
Namespace
Drupal\login_destination\FormCode
public function validateUriElement($element, FormStateInterface $form_state, $form) {
$uri = $this
->getUserEnteredStringAsUri($element['#value']);
$form_state
->setValueForElement($element, $uri);
// If getUserEnteredStringAsUri() mapped the entered value to a 'internal:'
// URI , ensure the raw value begins with '/', '?' or '#'.
// @todo '<front>' is valid input for BC reasons, may be removed by
// https://www.drupal.org/node/2421941
if (parse_url($uri, PHP_URL_SCHEME) === 'internal' && !in_array($element['#value'][0], [
'/',
'?',
'#',
'[',
], TRUE) && substr($element['#value'], 0, 7) !== '<front>' && substr($element['#value'], 0, 9) !== '<current>') {
$form_state
->setError($element, $this
->t('Manually entered paths should start with /, [, ? or #.'));
return;
}
}