Commit 95dc3178 authored by alexpott's avatar alexpott
Browse files

Issue #2448503 by amateescu: Convert the "Field edit" form to an actual entity form

parent 3425c65b
......@@ -364,7 +364,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
/**
* Returns a form for the field-level settings.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow
* administrators to configure field-level settings.
*
* @param array $form
......
......@@ -192,7 +192,7 @@ public function generateSampleItems($count = 1);
/**
* Returns a form for the default value input.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow
* administrators to configure instance-level default value.
*
* @param array $form
......@@ -208,7 +208,7 @@ public function defaultValuesForm(array &$form, FormStateInterface $form_state);
/**
* Validates the submitted default value.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow
* administrators to configure instance-level default value.
*
* @param array $element
......@@ -223,7 +223,7 @@ public function defaultValuesFormValidate(array $element, array &$form, FormStat
/**
* Processes the submitted default value.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow
* administrators to configure instance-level default value.
*
* @param array $element
......
......@@ -19,7 +19,7 @@ interface FormatterInterface extends PluginSettingsInterface {
/**
* Returns a form to configure settings for the formatter.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow
* administrators to configure the formatter. The field_ui module takes care
* of handling submitted form values.
*
......
......@@ -25,7 +25,7 @@ interface WidgetInterface extends WidgetBaseInterface {
/**
* Returns a form to configure settings for the widget.
*
* Invoked from \Drupal\field_ui\Form\FieldEditForm to allow
* Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow
* administrators to configure the widget. The field_ui module takes care of
* handling submitted form values.
*
......
......@@ -393,14 +393,14 @@ function testCommentFunctionality() {
// Test comment option change in field settings.
$edit = array(
'default_value_input[comment][0][status]' => CommentItemInterface::CLOSED,
'field[settings][anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT,
'settings[anonymous]' => COMMENT_ANONYMOUS_MAY_CONTACT,
);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-0');
$this->assertFieldChecked('edit-default-value-input-comment-0-status-1');
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
$this->assertFieldByName('field[settings][anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
$this->assertFieldByName('settings[anonymous]', COMMENT_ANONYMOUS_MAY_CONTACT);
// Add a new comment-type.
$bundle = CommentType::create(array(
......
......@@ -318,13 +318,13 @@ function content_translation_entity_extra_field_info() {
}
/**
* Implements hook_form_FORM_ID_alter() for 'field_ui_field_edit_form'.
* Implements hook_form_FORM_ID_alter() for 'field_config_edit_form'.
*/
function content_translation_form_field_ui_field_edit_form_alter(array &$form, FormStateInterface $form_state) {
$field = $form_state->get('field');
function content_translation_form_field_config_edit_form_alter(array &$form, FormStateInterface $form_state) {
$field = $form_state->getFormObject()->getEntity();
$bundle_is_translatable = \Drupal::service('content_translation.manager')->isEnabled($field->entity_type, $field->bundle);
$form['field']['translatable'] = array(
$form['translatable'] = array(
'#type' => 'checkbox',
'#title' => t('Users may translate this field'),
'#default_value' => $field->isTranslatable(),
......@@ -338,7 +338,7 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, F
$toggle_url = \Drupal::url('language.content_settings_page', array(), array(
'query' => drupal_get_destination(),
));
$form['field']['translatable']['#description'] = t('To configure translation for this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
$form['translatable']['#description'] = t('To configure translation for this field, <a href="@language-settings-url">enable language support</a> for this type.', array(
'@language-settings-url' => $toggle_url,
));
}
......@@ -347,8 +347,8 @@ function content_translation_form_field_ui_field_edit_form_alter(array &$form, F
module_load_include('inc', 'content_translation', 'content_translation.admin');
$element = content_translation_field_sync_widget($field);
if ($element) {
$form['field']['third_party_settings']['content_translation']['translation_sync'] = $element;
$form['field']['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10;
$form['third_party_settings']['content_translation']['translation_sync'] = $element;
$form['third_party_settings']['content_translation']['translation_sync']['#weight'] = -10;
}
}
}
......
......@@ -174,7 +174,7 @@ function testSettingsUI() {
// Test that also the Field UI form behaves correctly.
$translatable = !$translatable;
$edit = array('field[translatable]' => $translatable);
$edit = array('translatable' => $translatable);
$this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.body', $edit, t('Save settings'));
\Drupal::entityManager()->clearCachedFieldDefinitions();
$field = FieldConfig::loadByName('node', 'article', 'body');
......@@ -242,7 +242,7 @@ function testFieldTranslatableSettingsUI() {
// translatable.
$path = 'admin/structure/types/manage/article/fields/node.article.field_article_text';
$this->drupalGet($path);
$this->assertFieldByXPath('//input[@id="edit-field-translatable" and @disabled="disabled"]');
$this->assertFieldByXPath('//input[@id="edit-translatable" and @disabled="disabled"]');
$this->assertText('To configure translation for this field, enable language support for this type.', 'No translatable setting for field.');
// Tests that field has translatable setting if bundle is translatable.
......@@ -255,7 +255,7 @@ function testFieldTranslatableSettingsUI() {
);
$this->assertSettings('node', 'article', TRUE, $edit);
$this->drupalGet($path);
$this->assertFieldByXPath('//input[@id="edit-field-translatable" and not(@disabled) and @checked="checked"]');
$this->assertFieldByXPath('//input[@id="edit-translatable" and not(@disabled) and @checked="checked"]');
$this->assertNoText('To enable translation of this field, enable language support for this type.', 'Translatable setting for field available.');
}
......
......@@ -88,11 +88,11 @@ function testImageFieldSync() {
// Check that the alt and title fields are enabled for the image field.
$this->drupalLogin($this->editor);
$this->drupalGet('entity_test_mul/structure/' . $this->entityTypeId . '/fields/' . $this->entityTypeId . '.' . $this->entityTypeId . '.' . $this->fieldName);
$this->assertFieldChecked('edit-field-third-party-settings-content-translation-translation-sync-alt');
$this->assertFieldChecked('edit-field-third-party-settings-content-translation-translation-sync-title');
$this->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-alt');
$this->assertFieldChecked('edit-third-party-settings-content-translation-translation-sync-title');
$edit = array(
'field[third_party_settings][content_translation][translation_sync][alt]' => FALSE,
'field[third_party_settings][content_translation][translation_sync][title]' => FALSE,
'third_party_settings[content_translation][translation_sync][alt]' => FALSE,
'third_party_settings[content_translation][translation_sync][title]' => FALSE,
);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
......
......@@ -9,16 +9,13 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem;
use Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\OptGroup;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\TypedData\OptionsProviderInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\Core\Validation\Plugin\Validation\Constraint\AllowedValuesConstraint;
use Drupal\field\FieldStorageConfigInterface;
/**
* Alternative plugin implementation of the 'entity_reference' field type.
......@@ -128,7 +125,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
* {@inheritdoc}
*/
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$field = $form_state->get('field');
$field = $form_state->getFormObject()->getEntity();
// Get all selection plugins for this entity type.
$selection_plugins = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionGroups($this->getSetting('target_type'));
......@@ -192,7 +189,7 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
}
/**
* Form element validation handler; Stores the new values in the form state.
* Form element validation handler; Invokes selection plugin's validation.
*
* @param array $form
* The form where the settings form is being included in.
......@@ -200,13 +197,9 @@ public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
* The form state of the (entire) configuration form.
*/
public static function fieldSettingsFormValidate(array $form, FormStateInterface $form_state) {
if ($form_state->hasValue('field')) {
$form_state->unsetValue(array('field', 'settings', 'handler_submit'));
$form_state->get('field')->settings = $form_state->getValue(['field', 'settings']);
$handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($form_state->get('field'));
$handler->validateConfigurationForm($form, $form_state);
}
$field = $form_state->getFormObject()->getEntity();
$handler = \Drupal::service('plugin.manager.entity_reference_selection')->getSelectionHandler($field);
$handler->validateConfigurationForm($form, $form_state);
}
/**
......
......@@ -84,40 +84,40 @@ public function testFieldAdminHandler() {
$this->drupalPostForm(NULL, array(), t('Save field settings'));
// The base handler should be selected by default.
$this->assertFieldByName('field[settings][handler]', 'default:node');
$this->assertFieldByName('settings[handler]', 'default:node');
// The base handler settings should be displayed.
$entity_type_id = 'node';
$bundles = entity_get_bundles($entity_type_id);
foreach ($bundles as $bundle_name => $bundle_info) {
$this->assertFieldByName('field[settings][handler_settings][target_bundles][' . $bundle_name . ']');
$this->assertFieldByName('settings[handler_settings][target_bundles][' . $bundle_name . ']');
}
reset($bundles);
// Test the sort settings.
// Option 0: no sort.
$this->assertFieldByName('field[settings][handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
$this->assertFieldByName('settings[handler_settings][sort][field]', '_none');
$this->assertNoFieldByName('settings[handler_settings][sort][direction]');
// Option 1: sort by field.
$this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => 'nid'), 'field[settings][handler_settings][sort][field]');
$this->assertFieldByName('field[settings][handler_settings][sort][direction]', 'ASC');
$this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => 'nid'), 'settings[handler_settings][sort][field]');
$this->assertFieldByName('settings[handler_settings][sort][direction]', 'ASC');
// Test that a non-translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='nid']");
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='nid']");
// Test that a translatable base field is a sort option.
$this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='title']");
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='title']");
// Test that a configurable field is a sort option.
$this->assertFieldByXPath("//select[@name='field[settings][handler_settings][sort][field]']/option[@value='body.value']");
$this->assertFieldByXPath("//select[@name='settings[handler_settings][sort][field]']/option[@value='body.value']");
// Set back to no sort.
$this->drupalPostAjaxForm(NULL, array('field[settings][handler_settings][sort][field]' => '_none'), 'field[settings][handler_settings][sort][field]');
$this->assertNoFieldByName('field[settings][handler_settings][sort][direction]');
$this->drupalPostAjaxForm(NULL, array('settings[handler_settings][sort][field]' => '_none'), 'settings[handler_settings][sort][field]');
$this->assertNoFieldByName('settings[handler_settings][sort][direction]');
// Third step: confirm.
$this->drupalPostForm(NULL, array(
'field[required]' => '1',
'field[settings][handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles),
'required' => '1',
'settings[handler_settings][target_bundles][' . key($bundles) . ']' => key($bundles),
), t('Save settings'));
// Check that the field appears in the overview form.
......@@ -137,7 +137,7 @@ public function testFieldAdminHandler() {
);
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->assertFieldByName('field[settings][handler_settings][auto_create]');
$this->assertFieldByName('settings[handler_settings][auto_create]');
// Switch the target type to 'user' and check that the settings specific to
// its selection handler are displayed.
......@@ -147,13 +147,13 @@ public function testFieldAdminHandler() {
);
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->assertFieldByName('field[settings][handler_settings][filter][type]', '_none');
$this->assertFieldByName('settings[handler_settings][filter][type]', '_none');
// Try to select the views handler.
$edit = array(
'field[settings][handler]' => 'views',
'settings[handler]' => 'views',
);
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'field[settings][handler]');
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertResponse(200);
}
......@@ -242,7 +242,7 @@ public function createEntityReferenceField($target_type, $bundle = NULL) {
$storage_edit = $field_edit = array();
$storage_edit['settings[target_type]'] = $target_type;
if ($bundle) {
$field_edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
$field_edit['settings[handler_settings][target_bundles][' . $bundle . ']'] = TRUE;
}
$this->fieldUIAddNewField($bundle_path, $field_name, NULL, 'entity_reference', $storage_edit, $field_edit);
......
......@@ -146,7 +146,7 @@ public function testSupportedEntityTypesAndWidgets() {
'default_value_input[' . $this->fieldName . '][0][target_id]' => $referenced_entities[0]->label() . ' (' . $referenced_entities[0]->id() . ')',
);
if ($key == 'content') {
$field_edit['field[settings][handler_settings][target_bundles][' . $referenced_entities[0]->getEntityTypeId() . ']'] = TRUE;
$field_edit['settings[handler_settings][target_bundles][' . $referenced_entities[0]->getEntityTypeId() . ']'] = TRUE;
}
$this->drupalPostForm($this->entityType . '/structure/' . $this->bundle .'/fields/' . $this->entityType . '.' . $this->bundle . '.' . $this->fieldName, $field_edit, t('Save settings'));
// Ensure the configuration has the expected dependency on the entity that
......
......@@ -121,7 +121,7 @@ function testBooleanField() {
// Test if we can change the on label.
$on = $this->randomMachineName();
$edit = array(
'field[settings][on_label]' => $on,
'settings[on_label]' => $on,
);
$this->drupalPostForm('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name, $edit, t('Save settings'));
// Check if we see the updated labels in the creation form.
......@@ -179,8 +179,8 @@ function testBooleanField() {
// Test the boolean field settings.
$this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.' . $field_name);
$this->assertFieldById('edit-field-settings-on-label', $on);
$this->assertFieldById('edit-field-settings-off-label', $off);
$this->assertFieldById('edit-settings-on-label', $on);
$this->assertFieldById('edit-settings-off-label', $off);
}
}
......@@ -113,8 +113,8 @@ function testBooleanFormatterSettings() {
// Set up the field settings.
$this->drupalGet('admin/structure/types/manage/' . $this->bundle . '/fields/node.' . $this->bundle . '.' . $this->fieldName);
$this->drupalPostForm(NULL, array(
'field[settings][on_label]' => $values[0],
'field[settings][off_label]' => $values[1],
'settings[on_label]' => $values[0],
'settings[off_label]' => $values[1],
), 'Save settings');
// Open the Manage Display page and trigger the field settings form.
......
......@@ -517,7 +517,7 @@ function assertSetMinimumValue($field, $minimum_value) {
// Set the minimum value.
$edit = array(
'field[settings][min]' => $minimum_value,
'settings[min]' => $minimum_value,
);
$this->drupalPostForm($field_configuration_url, $edit, t('Save settings'));
// Check if an error message is shown.
......@@ -526,6 +526,6 @@ function assertSetMinimumValue($field, $minimum_value) {
$this->assertRaw(t('Saved %label configuration.', array('%label' => $field->getLabel())));
// Check if the minimum value was actually set.
$this->drupalGet($field_configuration_url);
$this->assertFieldById('edit-field-settings-min', $minimum_value, 'Minimal ' . gettype($minimum_value) .' value was set on a ' . $field->getType() . ' field.');
$this->assertFieldById('edit-settings-min', $minimum_value, 'Minimal ' . gettype($minimum_value) .' value was set on a ' . $field->getType() . ' field.');
}
}
......@@ -66,6 +66,7 @@ function field_ui_theme() {
*/
function field_ui_entity_type_build(array &$entity_types) {
/** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
$entity_types['field_config']->setFormClass('edit', 'Drupal\field_ui\Form\FieldConfigEditForm');
$entity_types['field_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldConfigDeleteForm');
$entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder');
......
......@@ -2,149 +2,101 @@
/**
* @file
* Contains \Drupal\field_ui\Form\FieldEditForm.
* Contains \Drupal\field_ui\Form\FieldConfigEditForm.
*/
namespace Drupal\field_ui\Form;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Form\FormBase;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Field\AllowedTagsXssTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\field\FieldConfigInterface;
use Drupal\field_ui\FieldUI;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for the field settings form.
*/
class FieldEditForm extends FormBase {
class FieldConfigEditForm extends EntityForm {
use AllowedTagsXssTrait;
/**
* The field being edited.
* The entity being used by this form.
*
* @var \Drupal\field\FieldConfigInterface
*/
protected $field;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface
*/
protected $entityManager;
/**
* Constructs a new field form.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
*/
public function __construct(EntityManagerInterface $entity_manager) {
$this->entityManager = $entity_manager;
}
protected $entity;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager')
);
}
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'field_ui_field_edit_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, FieldConfigInterface $field_config = NULL) {
$this->field = $field_config;
$form_state->set('field', $field_config);
$bundle = $this->field->bundle;
$entity_type = $this->field->entity_type;
$field_storage = $this->field->getFieldStorageDefinition();
$bundles = entity_get_bundles();
$field_storage = $this->entity->getFieldStorageDefinition();
$bundles = $this->entityManager->getBundleInfo($this->entity->getTargetEntityTypeId());
$form_title = $this->t('%field settings for %bundle', array(
'%field' => $this->field->getLabel(),
'%bundle' => $bundles[$entity_type][$bundle]['label'],
'%field' => $this->entity->getLabel(),
'%bundle' => $bundles[$this->entity->bundle]['label'],
));
$form['#title'] = $form_title;
$form['#field'] = $field_storage;
// Create an arbitrary entity object (used by the 'default value' widget).
$ids = (object) array('entity_type' => $this->field->entity_type, 'bundle' => $this->field->bundle, 'entity_id' => NULL);
$form['#entity'] = _field_create_entity_from_ids($ids);
$items = $form['#entity']->get($this->field->getName());
$item = $items->first() ?: $items->appendItem();
if (!empty($field_storage->locked)) {
if ($field_storage->isLocked()) {
$form['locked'] = array(
'#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->field->getLabel())),
'#markup' => $this->t('The field %field is locked and cannot be edited.', array('%field' => $this->entity->getLabel())),
);
return $form;
}
// Create a form structure for the field values.
$form['field'] = array(
'#tree' => TRUE,
);
// Build the non-configurable field values.
$form['field']['field_name'] = array(
'#type' => 'value',
'#value' => $this->field->getName(),
);
$form['field']['entity_type'] = array(
'#type' => 'value',
'#value' => $entity_type,
);
$form['field']['bundle'] = array(
'#type' => 'value',
'#value' => $bundle,
);
// Build the configurable field values.
$form['field']['label'] = array(
$form['label'] = array(
'#type' => 'textfield',
'#title' => $this->t('Label'),
'#default_value' => $this->field->getLabel() ?: $field_storage->getName(),
'#default_value' => $this->entity->getLabel() ?: $field_storage->getName(),
'#required' => TRUE,
'#weight' => -20,
);
$form['field']['description'] = array(
$form['description'] = array(
'#type' => 'textarea',
'#title' => $this->t('Help text'),
'#default_value' => $this->field->getDescription(),
'#default_value' => $this->entity->getDescription(),
'#rows' => 5,
'#description' => $this->t('Instructions to present to the user below this field on the editing form.<br />Allowed HTML tags: @tags', array('@tags' => $this->displayAllowedTags())) . '<br />' . $this->t('This field supports tokens.'),
'#weight' => -10,
);
$form['field']['required'] = array(
$form['required'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Required field'),
'#default_value' => $this->field->isRequired(),
'#default_value' => $this->entity->isRequired(),
'#weight' => -5,
);
// Create an arbitrary entity object (used by the 'default value' widget).
$ids = (object) array(
'entity_type' => $this->entity->getTargetEntityTypeId(),
'bundle' => $this->entity->bundle,
'entity_id' => NULL
);
$form['#entity'] = _field_create_entity_from_ids($ids);
$items = $form['#entity']->get($this->entity->getName());
$item = $items->first() ?: $items->appendItem();
// Add field settings for the field type and a container for third party
// settings that modules can add to via hook_form_FORM_ID_alter().
$form['field']['settings'] = $item->fieldSettingsForm($form, $form_state);
$form['field']['settings']['#weight'] = 10;
$form['field']['third_party_settings'] = array();
$form['field']['third_party_settings']['#weight'] = 11;
$form['settings'] = array(
'#tree' => TRUE,
'#weight' => 10,
);
$form['settings'] += $item->fieldSettingsForm($form, $form_state);
$form['third_party_settings'] = array(
'#tree' => TRUE,
'#weight' => 11,
);
// Add handling for default value.
if ($element = $items->defaultValuesForm($form, $form_state)) {
......@@ -152,33 +104,58 @@ public function buildForm(array $form, FormStateInterface $form_state, FieldConf
'#type' => 'details',
'#title' => $this->t('Default value'),
'#open' => TRUE,
'#tree' => TRUE,
'#description' => $this->t('The default value for this field, used when creating new content.'),
));
$form['field']['default_value'] = $element;
$form['default_value'] = $element;
}
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => $this->t('Save settings'),
'#button_type' => 'primary',
);
$form['actions']['delete'] = array(
'#type' => 'submit',
'#value' => $this->t('Delete field'),
'#submit' => array('::delete'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {