summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxjm2018-01-19 10:03:04 (GMT)
committerxjm2018-01-19 21:38:58 (GMT)
commitb594b5464a3167b8b8dff6a307814cb6b3661706 (patch)
treeab169e447e995144cb6c6c01d481a6811318bce5
parentc212be45999882e8d3d27b91b469719879c0c1a1 (diff)
Issue #2937889 by larowlan, Sam152: Regression: LinkWidget no longer supports base fields with optional title
(cherry picked from commit 7871cc00ee694a6f639ce58b07acf5499795aa9b)
-rw-r--r--core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php2
-rw-r--r--core/modules/link/tests/modules/link_test_base_field/link_test_base_field.info.yml8
-rw-r--r--core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module35
-rw-r--r--core/modules/link/tests/src/Functional/LinkFieldTest.php7
4 files changed, 50 insertions, 2 deletions
diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
index 2dc8ed6..56f6521 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 @@ class LinkWidget extends WidgetBase {
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 0000000..00e15df
--- /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 0000000..94730fa
--- /dev/null
+++ b/core/modules/link/tests/modules/link_test_base_field/link_test_base_field.module
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Contains main module functions.
+ */
+
+use Drupal\Core\Entity\EntityTypeInterface;
+use Drupal\Core\Field\BaseFieldDefinition;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+use Drupal\link\LinkItemInterface;
+
+/**
+ * Implements hook_entity_base_field_info().
+ */
+function link_test_base_field_entity_base_field_info(EntityTypeInterface $entity_type) {
+ $fields = [];
+ if ($entity_type->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 065a2bd..f32bf3c 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.