diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php b/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php index 7ab76e4..2eae2e6 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/widget/HiddenWidget.php @@ -7,7 +7,7 @@ namespace Drupal\field\Plugin\field\widget; -use Drupal\Core\Annotation\Plugin; +use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; use Drupal\field\Plugin\Type\Widget\WidgetBase; diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 99138f8..8ad2b99 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -389,7 +389,7 @@ function field_ui_field_type_options() { * If no field type is provided, returns a nested array of all widget types, * keyed by field type human name. */ -function field_ui_widget_type_options($field_type = NULL, $by_label = FALSE, $allow_hidden = TRUE) { +function field_ui_widget_type_options($field_type = NULL, $by_label = FALSE) { $options = &drupal_static(__FUNCTION__); if (!isset($options)) { @@ -397,9 +397,6 @@ function field_ui_widget_type_options($field_type = NULL, $by_label = FALSE, $al $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); uasort($widget_types, 'drupal_sort_weight'); - if (!$allow_hidden) { - unset($widget_types['field_hidden']); - } foreach ($widget_types as $name => $widget_type) { foreach ($widget_type['field_types'] as $widget_field_type) { // Check that the field type exists. @@ -658,7 +655,7 @@ function field_ui_widget_type_form($form, &$form_state, FieldInstance $instance) '#type' => 'select', '#title' => t('Widget type'), '#required' => TRUE, - '#options' => field_ui_widget_type_options($field['type'], FALSE, (bool) !$instance['required']), + '#options' => field_ui_widget_type_options($field['type']), '#default_value' => $instance->getWidget()->getPluginId(), '#description' => t('The type of form element you would like to present to the user when creating this field in the %type type.', array('%type' => $bundle_label)), ); @@ -694,6 +691,10 @@ function field_ui_widget_type_form_submit($form, &$form_state) { try { field_update_instance($instance); drupal_set_message(t('Changed the widget for field %label.', array('%label' => $instance['label']))); + + if ($instance['required'] && empty($instance['default value']) && $instance['widget']['type'] == 'field_hidden') { + drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $instance['label'])), 'warning'); + } } catch (Exception $e) { drupal_set_message(t('There was a problem changing the widget for field %label.', array('%label' => $instance['label'])), 'error'); @@ -850,13 +851,10 @@ function field_ui_field_edit_form($form, &$form_state, $instance) { '#weight' => -10, ); - $allow_required = $instance['widget']['type'] != 'field_hidden' ? TRUE : FALSE; $form['instance']['required'] = array( '#type' => 'checkbox', '#title' => t('Required field'), '#default_value' => !empty($instance['required']), - '#description' => !$allow_required ? t('This field uses the Hidden widget so it cannot be required.') : NULL, - '#disabled' => !$allow_required, '#weight' => -5, ); @@ -1019,6 +1017,10 @@ function field_ui_field_edit_form_submit($form, &$form_state) { drupal_set_message(t('Saved %label configuration.', array('%label' => $instance['label']))); + if ($instance['required'] && empty($instance['default value']) && $instance['widget']['type'] == 'field_hidden') { + drupal_set_message(t('Field %label is required and uses the "hidden" widget. You might want to configure a default value.', array('%label' => $instance['label'])), 'warning'); + } + $form_state['redirect'] = field_ui_next_destination($instance['entity_type'], $instance['bundle']); }