Commit ad555fa8 authored by catch's avatar catch

Issue #2084987 by andypost, Jalandhar: Remove usage of field_ui_default_value...

Issue #2084987 by andypost, Jalandhar: Remove usage of field_ui_default_value and recommend proper replacement
parent 8606a8dd
...@@ -318,7 +318,7 @@ protected function formSingleElement(FieldItemListInterface $items, $delta, arra ...@@ -318,7 +318,7 @@ protected function formSingleElement(FieldItemListInterface $items, $delta, arra
'widget' => $this, 'widget' => $this,
'items' => $items, 'items' => $items,
'delta' => $delta, '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); \Drupal::moduleHandler()->alter(array('field_widget_form', 'field_widget_' . $this->getPluginId() . '_form'), $element, $form_state, $context);
} }
...@@ -539,4 +539,17 @@ public static function isApplicable(FieldDefinitionInterface $field_definition) ...@@ -539,4 +539,17 @@ public static function isApplicable(FieldDefinitionInterface $field_definition)
return TRUE; 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');
}
} }
...@@ -589,6 +589,11 @@ function testHelpDescriptions() { ...@@ -589,6 +589,11 @@ function testHelpDescriptions() {
); );
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.field_image', $edit, t('Save settings')); $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( $edit = array(
'field[description]' => '<em>Test with a non upload field.', 'field[description]' => '<em>Test with a non upload field.',
); );
......
...@@ -84,7 +84,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ...@@ -84,7 +84,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
// Post-process the title field to make it conditionally required if URL is // 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 // non-empty. Omit the validation on the field edit form, since the field
// settings cannot be saved otherwise. // 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'); $element['#element_validate'][] = array($this, 'validateTitle');
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment