Issue #2051157 by yched, swentel: Fixed pass () as a param to ConfigFieldItem::settingsForm().

8.0.x
Alex Pott 2013-08-13 06:34:01 -05:00
parent 53731f9ecf
commit 7833e61c45
8 changed files with 20 additions and 16 deletions

View File

@ -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(

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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'));

View File

@ -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',

View File

@ -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;