diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 1ded194..38ef46c 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -7,7 +7,6 @@ use Drupal\Core\Field\WidgetBase; use Drupal\Core\Form\FormStateInterface; use Drupal\link\LinkItemInterface; -use Drupal\link\Plugin\Field\FieldType\LinkItem; use Symfony\Component\Validator\ConstraintViolation; use Symfony\Component\Validator\ConstraintViolationListInterface; @@ -149,9 +148,11 @@ public static function validateUriElement($element, FormStateInterface $form_sta case LinkItemInterface::LINK_EXTERNAL: $error_message = 'External links must be a full URL and include its protocol, such as %link_example.'; break; + case LinkItemInterface::LINK_INTERNAL: $error_message = 'Use a title of a piece of content to select it, or enter an internal path starting with /, ? or #.'; break; + // Error message for LinkItemInterface::LINK_GENERIC. default: $error_message = 'Use a title of a piece of content to select it, or enter an internal path starting with /, ? or #. External links must be a full URL and include its protocol, such as %link_example.'; diff --git a/core/modules/link/tests/src/Functional/LinkFieldTest.php b/core/modules/link/tests/src/Functional/LinkFieldTest.php index d5f388f..24ae724 100644 --- a/core/modules/link/tests/src/Functional/LinkFieldTest.php +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php @@ -139,7 +139,8 @@ public function testURLValidation() { 'entity:user/999999' => 'entity:user/999999', ]; - // Test external and internal URLs for 'link_type' = LinkItemInterface::LINK_GENERIC. + // Test external and internal URLs for + // 'link_type' = LinkItemInterface::LINK_GENERIC. $invalid_entries = $this->buildInvalidEntries(LinkItemInterface::LINK_GENERIC); $this->assertValidEntries($field_name, $valid_external_entries + $valid_internal_entries); $this->assertInvalidEntries($field_name, $invalid_entries['external'] + $invalid_entries['internal']); @@ -171,7 +172,7 @@ public function testURLValidation() { * Builds an array of invalid link entries with their error messages. * * @param int $link_type - * The link type identifier, such as LinkItemInterface::LINK_GENERIC, + * The link type identifier, such as LinkItemInterface::LINK_GENERIC. * * @return array * An associative array containing: @@ -189,9 +190,11 @@ protected function buildInvalidEntries($link_type) { case LinkItemInterface::LINK_EXTERNAL: $validation_error_field = 'External links must be a full URL and include its protocol, such as @link_example.'; break; + case LinkItemInterface::LINK_INTERNAL: $validation_error_field = 'Use a title of a piece of content to select it, or enter an internal path starting with /, ? or #.'; break; + // Error message for LinkItemInterface::LINK_GENERIC. default: $validation_error_field = 'Use a title of a piece of content to select it, or enter an internal path starting with /, ? or #. External links must be a full URL and include its protocol, such as @link_example.'; @@ -199,9 +202,9 @@ protected function buildInvalidEntries($link_type) { $invalid_entries = [ 'external' => [ - // Invalid protocol + // Invalid protocol. 'invalid://not-a-valid-protocol' => $validation_error_1, - // Missing host name + // Missing host name. 'http://' => $validation_error_1, // Missing protocol schema. 'www.example.com' => $validation_error_field, @@ -211,7 +214,7 @@ protected function buildInvalidEntries($link_type) { 'entity:non_existing_entity_type/yar' => $validation_error_1, // URI for an entity that doesn't exist, with an invalid ID. 'entity:user/invalid-parameter' => $validation_error_1, - ] + ], ]; return $invalid_entries;