From fd32349c97aa275f03b7ea4eb2ecbc53d1289a28 Mon Sep 17 00:00:00 2001 From: Dave Long <dave@longwaveconsulting.com> Date: Tue, 19 Mar 2024 22:10:34 +0000 Subject: [PATCH] Issue #3427500 by dreamleaf, adwivedi008, karanpagare: External link help text should give an https example instead of http --- core/modules/link/src/Plugin/Field/FieldType/LinkItem.php | 2 +- .../link/src/Plugin/Field/FieldWidget/LinkWidget.php | 4 ++-- .../modules/link/tests/src/Functional/LinkFieldUITest.php | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php index 2579dcbf9e05..b77acedf7ff2 100644 --- a/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php +++ b/core/modules/link/src/Plugin/Field/FieldType/LinkItem.php @@ -138,7 +138,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin $values['title'] = mt_rand(0, 1) ? $random->sentences(4) : ''; break; } - $values['uri'] = 'http://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, (count($tlds) - 1))]; + $values['uri'] = 'https://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, (count($tlds) - 1))]; } else { $values['uri'] = 'base:' . $random->name(mt_rand(1, 64)); diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 80c5704f343b..b596be82f73c 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -234,12 +234,12 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // If the field is configured to allow both internal and external links, // show a useful description. elseif ($this->supportsExternalLinks() && $this->supportsInternalLinks()) { - $element['uri']['#description'] = $this->t('Start typing the title of a piece of content to select it. You can also enter an internal path such as %add-node or an external URL such as %url. Enter %front to link to the front page. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%front' => '<front>', '%add-node' => '/node/add', '%url' => 'http://example.com', '%nolink' => '<nolink>', '%button' => '<button>']); + $element['uri']['#description'] = $this->t('Start typing the title of a piece of content to select it. You can also enter an internal path such as %add-node or an external URL such as %url. Enter %front to link to the front page. Enter %nolink to display link text only. Enter %button to display keyboard-accessible link text only.', ['%front' => '<front>', '%add-node' => '/node/add', '%url' => 'https://example.com', '%nolink' => '<nolink>', '%button' => '<button>']); } // If the field is configured to allow only external links, show a useful // description. elseif ($this->supportsExternalLinks() && !$this->supportsInternalLinks()) { - $element['uri']['#description'] = $this->t('This must be an external URL such as %url.', ['%url' => 'http://example.com']); + $element['uri']['#description'] = $this->t('This must be an external URL such as %url.', ['%url' => 'https://example.com']); } // Make uri required on the front-end when title filled-in. diff --git a/core/modules/link/tests/src/Functional/LinkFieldUITest.php b/core/modules/link/tests/src/Functional/LinkFieldUITest.php index dd4fe7370a0b..ac8d37f5b2fe 100644 --- a/core/modules/link/tests/src/Functional/LinkFieldUITest.php +++ b/core/modules/link/tests/src/Functional/LinkFieldUITest.php @@ -96,7 +96,7 @@ protected function providerTestFieldUI() { DRUPAL_OPTIONAL, ]; $link_types = [ - LinkItemInterface::LINK_EXTERNAL => 'http://example.com', + LinkItemInterface::LINK_EXTERNAL => 'https://example.com', LinkItemInterface::LINK_GENERIC => '', LinkItemInterface::LINK_INTERNAL => '<front>', ]; @@ -119,7 +119,7 @@ protected function providerTestFieldUI() { ]); // Use a unique label that contains some HTML. - $label = '<img src="http://example.com">' . $id; + $label = '<img src="https://example.com">' . $id; yield [ $cardinality, @@ -191,8 +191,8 @@ public function runFieldUIItem($cardinality, $link_type, $title, $label, $field_ $this->drupalGet($add_path); $expected_help_texts = [ - LinkItemInterface::LINK_EXTERNAL => 'This must be an external URL such as <em class="placeholder">http://example.com</em>.', - LinkItemInterface::LINK_GENERIC => 'You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">http://example.com</em>. Enter <em class="placeholder"><front></em> to link to the front page. Enter <em class="placeholder"><nolink></em> to display link text only', + LinkItemInterface::LINK_EXTERNAL => 'This must be an external URL such as <em class="placeholder">https://example.com</em>.', + LinkItemInterface::LINK_GENERIC => 'You can also enter an internal path such as <em class="placeholder">/node/add</em> or an external URL such as <em class="placeholder">https://example.com</em>. Enter <em class="placeholder"><front></em> to link to the front page. Enter <em class="placeholder"><nolink></em> to display link text only', LinkItemInterface::LINK_INTERNAL => rtrim(Url::fromRoute('<front>', [], ['absolute' => TRUE])->toString(), '/'), ]; -- GitLab