diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 143ad1d..2abadb2 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -190,6 +190,10 @@ public function isExternal() { * @return string */ public function getRouteName() { + if ($this->isExternal()) { + throw new \UnexpectedValueException('External URLs do not have an internal route name.'); + } + return $this->routeName; } @@ -199,6 +203,10 @@ public function getRouteName() { * @return array */ public function getRouteParameters() { + if ($this->isExternal()) { + throw new \UnexpectedValueException('External URLs do not have internal route parameters.'); + } + return $this->routeParameters; } @@ -305,6 +313,7 @@ public function getPath() { if (!$this->isExternal()) { throw new \UnexpectedValueException('Internal URLs do not have external paths.'); } + return $this->path; } diff --git a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php index 1afa70e..4bf0b63 100644 --- a/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/lib/Drupal/link/Plugin/Field/FieldType/LinkItem.php @@ -20,7 +20,7 @@ * @FieldType( * id = "link", * label = @Translation("Link"), - * description = @Translation("Stores a URL string, optional varchar link text, and optional blob of options to assemble a link."), + * description = @Translation("Stores a URL string for external links or route name and parameters for internal links, an optional varchar link text and an optional blob of options to assemble a link."), * instance_settings = { * "url_type" = \Drupal\link\LinkItemInterface::LINK_GENERIC, * "title" = "1" @@ -106,9 +106,9 @@ public function instanceSettingsForm(array $form, array &$form_state) { '#title' => t('Allowed url type'), '#default_value' => $this->getSetting('url_type'), '#options' => array( - static::LINK_INTERNAL => t('Internal urls only'), - static::LINK_EXTERNAL => t('External urls only'), - static::LINK_GENERIC => t('Both internal and external urls'), + static::LINK_INTERNAL => t('Internal URLs only'), + static::LINK_EXTERNAL => t('External URLs only'), + static::LINK_GENERIC => t('Both internal and external URLs'), ), ); 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 9dfd710..e54159f 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 @@ -178,7 +178,7 @@ public function validateUrl(&$element, &$form_state, $form) { $url_is_valid = TRUE; // Validate only if the field type supports internal URLs. - if ($element['url']['#value'] !== '' && $url_type & LinkItemInterface::LINK_INTERNAL) { + if ($element['url']['#value'] !== '') { try { $url = Url::createFromPath($element['url']['#value']); diff --git a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php b/core/tests/Drupal/Tests/Core/ExternalUrlTest.php index f355b97..37f1a40 100644 --- a/core/tests/Drupal/Tests/Core/ExternalUrlTest.php +++ b/core/tests/Drupal/Tests/Core/ExternalUrlTest.php @@ -153,10 +153,12 @@ public function testToArray(Url $url) { * * @depends testCreateFromPath * + * @expectedException \UnexpectedValueException + * * @covers ::getRouteName() */ public function testGetRouteName(Url $url) { - $this->assertSame(NULL, $url->getRouteName()); + $url->getRouteName(); } /** @@ -164,10 +166,12 @@ public function testGetRouteName(Url $url) { * * @depends testCreateFromPath * + * @expectedException \UnexpectedValueException + * * @covers ::getRouteParameters() */ public function testGetRouteParameters(Url $url) { - $this->assertSame(array(), $url->getRouteParameters()); + $url->getRouteParameters(); } /**