summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2014-12-08 11:10:27 (GMT)
committerNathaniel Catchpole2014-12-08 11:10:27 (GMT)
commitad555fa8a30c93d6cdf5de039e80a1dbb3d0c5b4 (patch)
tree7375f0aaeff136d3d0f7901d5b2147d7ac2f7eab
parent8606a8dd436f16e4ed635733196abd97bc7cbcca (diff)
Issue #2084987 by andypost, Jalandhar: Remove usage of field_ui_default_value and recommend proper replacement
-rw-r--r--core/lib/Drupal/Core/Field/WidgetBase.php15
-rw-r--r--core/modules/field_ui/src/Tests/ManageFieldsTest.php5
-rw-r--r--core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php2
3 files changed, 20 insertions, 2 deletions
diff --git a/core/lib/Drupal/Core/Field/WidgetBase.php b/core/lib/Drupal/Core/Field/WidgetBase.php
index 7b36c56..4d3d666 100644
--- a/core/lib/Drupal/Core/Field/WidgetBase.php
+++ b/core/lib/Drupal/Core/Field/WidgetBase.php
@@ -318,7 +318,7 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
'widget' => $this,
'items' => $items,
'delta' => $delta,
- 'default' => !empty($entity->field_ui_default_value),
+ 'default' => $this->isDefaultValueWidget($form_state),
);
\Drupal::moduleHandler()->alter(array('field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'), $element, $form_state, $context);
}
@@ -539,4 +539,17 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
return TRUE;
}
+ /**
+ * Returns whether the widget used for default value form.
+ *
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ *
+ * @return bool
+ * TRUE if a widget used to input default value, FALSE otherwise.
+ */
+ protected function isDefaultValueWidget(FormStateInterface $form_state) {
+ return (bool) $form_state->get('default_value_widget');
+ }
+
}
diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
index 955034c..8c2adb6 100644
--- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php
+++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php
@@ -589,6 +589,11 @@ class ManageFieldsTest extends WebTestBase {
);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image', $edit, t('Save settings'));
+ // Check that hook_field_widget_form_alter() does believe this is the
+ // default value form.
+ $this->drupalGet('admin/structure/types/manage/article/fields/node.article.field_tags');
+ $this->assertText('From hook_field_widget_form_alter(): Default form is true.', 'Default value form in hook_field_widget_form_alter().');
+
$edit = array(
'field[description]' => '<em>Test with a non upload field.',
);
diff --git a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
index e0666d9..1d5ab73 100644
--- a/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
+++ b/core/modules/link/src/Plugin/Field/FieldWidget/LinkWidget.php
@@ -84,7 +84,7 @@ class LinkWidget extends WidgetBase {
// 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
// settings cannot be saved otherwise.
- if (!$form_state->get('default_value_widget') && $this->getFieldSetting('title') == DRUPAL_REQUIRED) {
+ if (!$this->isDefaultValueWidget($form_state) && $this->getFieldSetting('title') == DRUPAL_REQUIRED) {
$element['#element_validate'][] = array($this, 'validateTitle');
}