From 1efd2ad05f5fc62f6b62a83a7da9f4dcbf9f83cb Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 17 Apr 2014 10:15:43 -0700 Subject: [PATCH] Issue #2231413 by blueminds, tim.plunkett: Link field does not accept a valid path alias. --- .../lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php | 6 ++++++ core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php | 3 +++ 2 files changed, 9 insertions(+) diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php index b9a229aa4fe..baf1eb57ce8 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldWidget/LinkWidget.php @@ -207,6 +207,12 @@ class LinkWidget extends WidgetBase { try { $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->setOption('query', $parsed_url['query']); $url->setOption('fragment', $parsed_url['fragment']); diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index e335fd797cf..01f7ed7f1b5 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -103,12 +103,15 @@ class LinkFieldTest extends WebTestBase { $this->assertFieldByName("{$field_name}[0][url]", '', 'Link URL field is displayed'); $this->assertRaw('placeholder="http://example.com"'); + // Create a path alias. + \Drupal::service('path.alias_storage')->save('admin', 'a/path/alias'); // Define some valid URLs. $valid_external_entries = array( 'http://www.example.com/', ); $valid_internal_entries = array( 'entity_test/add', + 'a/path/alias', ); // Define some invalid URLs.