Skip to content
Snippets Groups Projects
Commit 1efd2ad0 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #2231413 by blueminds, tim.plunkett: Link field does not accept a valid path alias.

parent 6f0f10b2
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -207,6 +207,12 @@ public function massageFormValues(array $values, array $form, array &$form_state ...@@ -207,6 +207,12 @@ public function massageFormValues(array $values, array $form, array &$form_state
try { try {
$parsed_url = UrlHelper::parse($value['url']); $parsed_url = UrlHelper::parse($value['url']);
// If internal links are supported, look up whether the given value is
// a path alias and store the system path instead.
if ($this->supportsInternalLinks() && !UrlHelper::isExternal($value['url'])) {
$parsed_url['path'] = \Drupal::service('path.alias_manager.cached')->getSystemPath($parsed_url['path']);
}
$url = Url::createFromPath($parsed_url['path']); $url = Url::createFromPath($parsed_url['path']);
$url->setOption('query', $parsed_url['query']); $url->setOption('query', $parsed_url['query']);
$url->setOption('fragment', $parsed_url['fragment']); $url->setOption('fragment', $parsed_url['fragment']);
......
...@@ -103,12 +103,15 @@ function testURLValidation() { ...@@ -103,12 +103,15 @@ function testURLValidation() {
$this->assertFieldByName("{$field_name}[0][url]", '', 'Link URL field is displayed'); $this->assertFieldByName("{$field_name}[0][url]", '', 'Link URL field is displayed');
$this->assertRaw('placeholder="http://example.com"'); $this->assertRaw('placeholder="http://example.com"');
// Create a path alias.
\Drupal::service('path.alias_storage')->save('admin', 'a/path/alias');
// Define some valid URLs. // Define some valid URLs.
$valid_external_entries = array( $valid_external_entries = array(
'http://www.example.com/', 'http://www.example.com/',
); );
$valid_internal_entries = array( $valid_internal_entries = array(
'entity_test/add', 'entity_test/add',
'a/path/alias',
); );
// Define some invalid URLs. // Define some invalid URLs.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment