diff -u b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php --- b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -244,15 +244,15 @@ ]; } - $title_settings = $this->getFieldSetting('title'); + $title_setting = $this->getFieldSetting('title'); $element['title'] = [ '#type' => 'textfield', '#title' => $this->t('Link text'), '#placeholder' => $this->getSetting('placeholder_title'), - '#default_value' => $title_settings === DRUPAL_DISABLED ? NULL : ($items[$delta]->title ?? NULL), + '#default_value' => $title_setting === DRUPAL_DISABLED ? NULL : ($items[$delta]->title ?? NULL), '#maxlength' => 255, - '#access' => $title_settings != DRUPAL_DISABLED, - '#required' => $title_settings === DRUPAL_REQUIRED && $element['#required'], + '#access' => $title_setting != DRUPAL_DISABLED, + '#required' => $title_setting === DRUPAL_REQUIRED && $element['#required'], ]; // Post-process the title field to make it conditionally required if URL is // non-empty. Omit the validation on the field edit form, since the field @@ -260,7 +260,7 @@ // // Validate that title field is filled out (regardless of uri) when it is a // required field. - if (!$this->isDefaultValueWidget($form_state) && $title_settings === DRUPAL_REQUIRED) { + if (!$this->isDefaultValueWidget($form_state) && $title_setting === DRUPAL_REQUIRED) { $element['#element_validate'][] = [static::class, 'validateTitleElement']; $element['#element_validate'][] = [static::class, 'validateTitleNoLink']; @@ -282,7 +282,7 @@ // Ensure that a URI is always entered when an optional title field is // submitted. - if (!$this->isDefaultValueWidget($form_state) && $title_settings == DRUPAL_OPTIONAL) { + if (!$this->isDefaultValueWidget($form_state) && $title_setting == DRUPAL_OPTIONAL) { $element['#element_validate'][] = [static::class, 'validateTitleNoLink']; } @@ -299,7 +299,7 @@ if ($this->fieldDefinition->getFieldStorageDefinition()->getCardinality() == 1) { // If the link title is disabled, use the field definition label as the // title of the 'uri' element. - if ($title_settings == DRUPAL_DISABLED) { + if ($title_setting == DRUPAL_DISABLED) { $element['uri']['#title'] = $element['#title']; // By default the field description is added to the title field. Since // the title field is disabled, we add the description, if given, to the diff -u b/core/modules/link/tests/src/Functional/LinkFieldTest.php b/core/modules/link/tests/src/Functional/LinkFieldTest.php --- b/core/modules/link/tests/src/Functional/LinkFieldTest.php +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php @@ -372,22 +372,6 @@ $output = $this->renderTestEntity($id); $expected_link = (string) Link::fromTextAndUrl($title, Url::fromUri($value))->toString(); $this->assertStringContainsString($expected_link, $output); - - // Verify that if the title field is disabled, the link field with correct - // text is rendered. - $this->field->setSetting('title', DRUPAL_DISABLED); - $this->field->save(); - - $value = 'http://www.example.net/'; - $edit = [ - "{$field_name}[0][uri]" => $value, - ]; - $this->submitForm($edit, 'Save'); - $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been updated.'); - - $output = $this->renderTestEntity($id); - $expected_link = (string) Link::fromTextAndUrl($value, Url::fromUri($value))->toString(); - $this->assertStringContainsString($expected_link, $output); } /** @@ -405,6 +389,22 @@ $output = $this->renderTestEntity($id); $expected_link = (string) Link::fromTextAndUrl($title, Url::fromUri($value))->toString(); $this->assertStringContainsString($expected_link, $output); + + // Verify that if the title field is disabled, the link field with correct + // text is rendered. + $this->field->setSetting('title', DRUPAL_DISABLED); + $this->field->save(); + + $value = 'http://www.example.net/'; + $edit = [ + "{$field_name}[0][uri]" => $value, + ]; + $this->submitForm($edit, 'Save'); + $this->assertSession()->pageTextContains('entity_test ' . $id . ' has been updated.'); + + $output = $this->renderTestEntity($id); + $expected_link = (string) Link::fromTextAndUrl($value, Url::fromUri($value))->toString(); + $this->assertStringContainsString($expected_link, $output); } /**