diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 9c97caa..f838540 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -226,6 +226,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen // settings cannot be saved otherwise. if (!$this->isDefaultValueWidget($form_state) && $this->getFieldSetting('title') == DRUPAL_REQUIRED) { $element['#element_validate'][] = array(get_called_class(), 'validateTitleElement'); + // Mark field as required, if parent is required. + $element['title']['#required'] = $element['#required']; } // Exposing the attributes array in the widget is left for alternate and more diff --git a/core/modules/link/src/Tests/LinkFieldTest.php b/core/modules/link/src/Tests/LinkFieldTest.php index eada494..4eb64b3 100644 --- a/core/modules/link/src/Tests/LinkFieldTest.php +++ b/core/modules/link/src/Tests/LinkFieldTest.php @@ -275,6 +275,8 @@ function testLinkTitle() { // Verify that the link text is required, if the URL is non-empty. $edit = array( "{$field_name}[0][uri]" => 'http://www.example.com', + // if the URL is non-empty, text field should also not be empty. + "{$field_name}[0][title]" => 'Example', ); $this->drupalPostForm(NULL, $edit, t('Save')); $this->assertText(t('@name field is required.', array('@name' => t('Link text'))));