Issue #2051157 by yched, swentel: Fixed pass () as a param to ConfigFieldItem::settingsForm().
parent
53731f9ecf
commit
7833e61c45
|
@ -76,7 +76,7 @@ class DateTimeItem extends ConfigFieldItemBase implements PrepareCacheInterface
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function settingsForm(array $form, array &$form_state) {
|
public function settingsForm(array $form, array &$form_state, $has_data) {
|
||||||
$element = array();
|
$element = array();
|
||||||
|
|
||||||
$element['datetime_type'] = array(
|
$element['datetime_type'] = array(
|
||||||
|
|
|
@ -125,11 +125,11 @@ class ConfigEntityReferenceItemBase extends EntityReferenceItem implements Confi
|
||||||
* Copied from \Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem,
|
* Copied from \Drupal\field\Plugin\field\field_type\LegacyConfigFieldItem,
|
||||||
* since we cannot extend it.
|
* 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')) {
|
if ($callback = $this->getLegacyCallback('settings_form')) {
|
||||||
// hook_field_settings_form() used to receive the $instance (not actually
|
// hook_field_settings_form() used to receive the $instance (not actually
|
||||||
// needed), and the value of field_has_data().
|
// 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();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ abstract class ConfigFieldItemBase extends FieldItemBase implements ConfigFieldI
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function settingsForm(array $form, array &$form_state) {
|
public function settingsForm(array $form, array &$form_state, $has_data) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,18 +60,25 @@ interface ConfigFieldItemInterface extends FieldItemInterface {
|
||||||
* Returns a form for the field-level settings.
|
* Returns a form for the field-level settings.
|
||||||
*
|
*
|
||||||
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow administrators to
|
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow administrators to
|
||||||
* configure field-level settings. If the field already has data, the form
|
* configure field-level settings.
|
||||||
* should only include the settings that are safe to change.
|
*
|
||||||
|
* 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
|
* @param array $form
|
||||||
* The form where the settings form is being included in.
|
* The form where the settings form is being included in.
|
||||||
* @param array $form_state
|
* @param array $form_state
|
||||||
* The form state of the (entire) configuration form.
|
* The form state of the (entire) configuration form.
|
||||||
|
* @param bool $has_data
|
||||||
|
* TRUE if the field already has data, FALSE if not.
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* The form definition for the field settings.
|
* 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.
|
* Returns a form for the instance-level settings.
|
||||||
|
|
|
@ -55,11 +55,11 @@ abstract class LegacyConfigFieldItem extends ConfigFieldItemBase implements Prep
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@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')) {
|
if ($callback = $this->getLegacyCallback('settings_form')) {
|
||||||
// hook_field_settings_form() used to receive the $instance (not actually
|
// hook_field_settings_form() used to receive the $instance (not actually
|
||||||
// needed), and the value of field_has_data().
|
// 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();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ class FieldEditForm implements FormInterface, ControllerInterface {
|
||||||
// FieldItem.
|
// FieldItem.
|
||||||
$ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL);
|
$ids = (object) array('entity_type' => $this->instance['entity_type'], 'bundle' => $this->instance['bundle'], 'entity_id' => NULL);
|
||||||
$entity = _field_create_entity_from_ids($ids);
|
$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'] = array('#type' => 'actions');
|
||||||
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings'));
|
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save field settings'));
|
||||||
|
|
|
@ -67,10 +67,9 @@ class DecimalItem extends NumberItemBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function settingsForm(array $form, array &$form_state) {
|
public function settingsForm(array $form, array &$form_state, $has_data) {
|
||||||
$element = array();
|
$element = array();
|
||||||
$settings = $this->getFieldSettings();
|
$settings = $this->getFieldSettings();
|
||||||
$has_data = $this->getInstance()->getField()->hasData();
|
|
||||||
|
|
||||||
$element['precision'] = array(
|
$element['precision'] = array(
|
||||||
'#type' => 'select',
|
'#type' => 'select',
|
||||||
|
|
|
@ -83,7 +83,7 @@ class TextItem extends TextItemBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function settingsForm(array $form, array &$form_state) {
|
public function settingsForm(array $form, array &$form_state, $has_data) {
|
||||||
$element = array();
|
$element = array();
|
||||||
|
|
||||||
$element['max_length'] = array(
|
$element['max_length'] = array(
|
||||||
|
@ -93,9 +93,7 @@ class TextItem extends TextItemBase {
|
||||||
'#required' => TRUE,
|
'#required' => TRUE,
|
||||||
'#description' => t('The maximum length of the field in characters.'),
|
'#description' => t('The maximum length of the field in characters.'),
|
||||||
'#min' => 1,
|
'#min' => 1,
|
||||||
// @todo: If $has_data, add a validate handler that only allows
|
'#disabled' => $has_data,
|
||||||
// max_length to increase.
|
|
||||||
'#disabled' => $this->getInstance()->getField()->hasData(),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $element;
|
return $element;
|
||||||
|
|
Loading…
Reference in New Issue