diff --git a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/field_type/DateTimeItem.php b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/field_type/DateTimeItem.php index 6f02eda9bac..558ca474426 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Plugin/field/field_type/DateTimeItem.php +++ b/core/modules/datetime/lib/Drupal/datetime/Plugin/field/field_type/DateTimeItem.php @@ -76,7 +76,7 @@ class DateTimeItem extends ConfigFieldItemBase implements PrepareCacheInterface /** * {@inheritdoc} */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { $element = array(); $element['datetime_type'] = array( diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php index 80b69b69c12..92443245d41 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigEntityReferenceItemBase.php @@ -125,11 +125,11 @@ class ConfigEntityReferenceItemBase extends EntityReferenceItem implements Confi * Copied from \Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem, * since we cannot extend it. */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $this->getInstance()->getField()->hasData()); + return $callback($this->getInstance()->getField(), $this->getInstance(), $has_data); } return array(); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php index 743ad5c7145..388ccbe0c08 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemBase.php @@ -34,7 +34,7 @@ abstract class ConfigFieldItemBase extends FieldItemBase implements ConfigFieldI /** * {@inheritdoc} */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { return array(); } diff --git a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php index f37afa0dbe6..a584640d9c3 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php +++ b/core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigFieldItemInterface.php @@ -60,18 +60,25 @@ interface ConfigFieldItemInterface extends FieldItemInterface { * Returns a form for the field-level settings. * * Invoked from \Drupal\field_ui\Form\FieldEditForm to allow administrators to - * configure field-level settings. If the field already has data, the form - * should only include the settings that are safe to change. + * configure field-level settings. + * + * Field storage might reject field definition changes that affect the field + * storage schema if the field already has data. When the $has_data parameter + * is TRUE, the form should not allow changing the settings that take part in + * the schema() method. It is recommended to set #access to FALSE on the + * corresponding elements. * * @param array $form * The form where the settings form is being included in. * @param array $form_state * The form state of the (entire) configuration form. + * @param bool $has_data + * TRUE if the field already has data, FALSE if not. * * @return * The form definition for the field settings. */ - public function settingsForm(array $form, array &$form_state); + public function settingsForm(array $form, array &$form_state, $has_data); /** * Returns a form for the instance-level settings. diff --git a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php index 0bad0d0dfd4..26e0a105b68 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php +++ b/core/modules/field/lib/Drupal/field/Plugin/field/field_type/LegacyConfigFieldItem.php @@ -55,11 +55,11 @@ abstract class LegacyConfigFieldItem extends ConfigFieldItemBase implements Prep /** * {@inheritdoc} */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { if ($callback = $this->getLegacyCallback('settings_form')) { // hook_field_settings_form() used to receive the $instance (not actually // needed), and the value of field_has_data(). - return $callback($this->getInstance()->getField(), $this->getInstance(), $this->getInstance()->getField()->hasData()); + return $callback($this->getInstance()->getField(), $this->getInstance(), $has_data); } return array(); } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php index 305596fe08b..f40e32a33b9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldEditForm.php @@ -138,7 +138,7 @@ class FieldEditForm implements FormInterface, ControllerInterface { // FieldItem. $ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL); $entity = _field_create_entity_from_ids($ids); - $form['field']['settings'] += $this->getFieldItem($entity, $field['field_name'])->settingsForm($form, $form_state); + $form['field']['settings'] += $this->getFieldItem($entity, $field['field_name'])->settingsForm($form, $form_state, $field->hasData()); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings')); diff --git a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php index d7ca60f55f3..927189983da 100644 --- a/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php +++ b/core/modules/number/lib/Drupal/number/Plugin/field/field_type/DecimalItem.php @@ -67,10 +67,9 @@ class DecimalItem extends NumberItemBase { /** * {@inheritdoc} */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { $element = array(); $settings = $this->getFieldSettings(); - $has_data = $this->getInstance()->getField()->hasData(); $element['precision'] = array( '#type' => 'select', diff --git a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php index d048caf5653..644a2a96894 100644 --- a/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php +++ b/core/modules/text/lib/Drupal/text/Plugin/field/field_type/TextItem.php @@ -83,7 +83,7 @@ class TextItem extends TextItemBase { /** * {@inheritdoc} */ - public function settingsForm(array $form, array &$form_state) { + public function settingsForm(array $form, array &$form_state, $has_data) { $element = array(); $element['max_length'] = array( @@ -93,9 +93,7 @@ class TextItem extends TextItemBase { '#required' => TRUE, '#description' => t('The maximum length of the field in characters.'), '#min' => 1, - // @todo: If $has_data, add a validate handler that only allows - // max_length to increase. - '#disabled' => $this->getInstance()->getField()->hasData(), + '#disabled' => $has_data, ); return $element;