diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php index 2dc8ed6760033213a92d67c0db3ee903ee760072..56f65218e5aca68269702df5fa85260139ba8a1a 100644 --- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php +++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php @@ -227,7 +227,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen if (!$element['title']['#required']) { // Make title required on the front-end when URI filled-in. - $field_name = $this->fieldDefinition->get('field_name'); + $field_name = $this->fieldDefinition->getName(); $parents = $element['#field_parents']; $parents[] = $field_name; diff --git a/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.info.yml b/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.info.yml new file mode 100644 index 0000000000000000000000000000000000000000..00e15df055739fc5d1a79fec08345683cc7898cb --- /dev/null +++ b/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.info.yml @@ -0,0 +1,8 @@ +name: Link test base field +description: Tests link field as an optional base field +type: module +core: 8.x +hidden: true +dependencies: + - link + - entity_test diff --git a/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module b/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module new file mode 100644 index 0000000000000000000000000000000000000000..94730fa4f62b49ed7be0c1294e0c3ad1b525e084 --- /dev/null +++ b/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module @@ -0,0 +1,35 @@ +id() === 'entity_test') { + $fields['links'] = BaseFieldDefinition::create('link') + ->setLabel(t('Links')) + ->setRevisionable(TRUE) + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setDescription(t('Add links to the entity.')) + ->setRequired(FALSE) + ->setSettings([ + 'link_type' => LinkItemInterface::LINK_GENERIC, + 'title' => DRUPAL_REQUIRED, + ]) + ->setDisplayOptions('form', [ + 'type' => 'link_default', + 'weight' => 49, + ]); + } + return $fields; +} diff --git a/core/modules/link/tests/src/Functional/LinkFieldTest.php b/core/modules/link/tests/src/Functional/LinkFieldTest.php index 065a2bddec5e395f7fd3f4ae5cf157fdba6f1eee..f32bf3c45b8282671688f50b935711dbf9831ce6 100644 --- a/core/modules/link/tests/src/Functional/LinkFieldTest.php +++ b/core/modules/link/tests/src/Functional/LinkFieldTest.php @@ -24,7 +24,12 @@ class LinkFieldTest extends BrowserTestBase { * * @var array */ - public static $modules = ['entity_test', 'link', 'node']; + public static $modules = [ + 'entity_test', + 'link', + 'node', + 'link_test_base_field', + ]; /** * A field to use in this test class.