Commit 7833e61c authored by alexpott's avatar alexpott
Browse files

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

parent 53731f9e
......@@ -76,7 +76,7 @@ public static function schema(FieldInterface $field) {
/**
* {@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(
......
......@@ -125,11 +125,11 @@ public function isEmpty() {
* 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();
}
......
......@@ -34,7 +34,7 @@ public function getInstance() {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
public function settingsForm(array $form, array &$form_state, $has_data) {
return array();
}
......
......@@ -60,18 +60,25 @@ public static function schema(FieldInterface $field);
* 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.
......
......@@ -55,11 +55,11 @@ public function isEmpty() {
/**
* {@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();
}
......
......@@ -138,7 +138,7 @@ public function buildForm(array $form, array &$form_state, FieldInstanceInterfac
// 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'));
......
......@@ -67,10 +67,9 @@ public static function schema(FieldInterface $field) {
/**
* {@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',
......
......@@ -83,7 +83,7 @@ public function getConstraints() {
/**
* {@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 @@ public function settingsForm(array $form, array &$form_state) {
'#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;
......
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