diff --git a/core/lib/Drupal/Core/Field/FieldItemInterface.php b/core/lib/Drupal/Core/Field/FieldItemInterface.php index f74b3f7f8180be8554b42230cf27188d7aecc3c3..1b60015c0beb3af3b586aba24b75adeb38225781 100644 --- a/core/lib/Drupal/Core/Field/FieldItemInterface.php +++ b/core/lib/Drupal/Core/Field/FieldItemInterface.php @@ -340,7 +340,7 @@ public static function fieldSettingsFromConfigData(array $settings); /** * Returns a form for the storage-level settings. * - * Invoked from \Drupal\field_ui\Form\FieldStorageEditForm to allow + * Invoked from \Drupal\field_ui\Form\FieldStorageConfigEditForm to allow * administrators to configure storage-level settings. * * Field storage might reject settings changes that affect the field diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index f1a4c9cc57bf8640edc8cfadfb2b478b7d6462f4..04d1f4276ef7a835a01c7b9bd96b9647b9127058 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -327,14 +327,14 @@ function comment_form_field_ui_display_overview_form_alter(&$form, FormStateInte } /** - * Implements hook_form_FORM_ID_alter(). + * Implements hook_form_FORM_ID_alter() for 'field_storage_config_edit_form'. */ -function comment_form_field_ui_field_storage_edit_form_alter(&$form, FormStateInterface $form_state) { - if ($form['#field']->getType() == 'comment') { +function comment_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state) { + if ($form_state->getFormObject()->getEntity()->getType() == 'comment') { // We only support posting one comment at the time so it doesn't make sense // to let the site builder choose anything else. - $form['field_storage']['cardinality_container']['cardinality']['#default_value'] = 1; - $form['field_storage']['cardinality_container']['#access'] = FALSE; + $form['cardinality_container']['cardinality']['#default_value'] = 1; + $form['cardinality_container']['#access'] = FALSE; } } diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index 3ce7da69f756ae52435b96ff19d5b5ce5c0600df..c66f08ae42b28272dee8da259529c1d9f82755e6 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -129,7 +129,7 @@ public function testCommentFieldCreate() { // Select a comment type and try to save again. $edit = array( - 'field_storage[settings][comment_type]' => 'user_comment_type', + 'settings[comment_type]' => 'user_comment_type', ); $this->drupalPostForm('admin/config/people/accounts/fields/user.user.field_user_comment/storage', $edit, t('Save field settings')); // We shouldn't get an error message. diff --git a/core/modules/comment/src/Tests/CommentNonNodeTest.php b/core/modules/comment/src/Tests/CommentNonNodeTest.php index d1358edc6e13d132a96e5ddef6b0373239525c33..1f3ad3c7f2d0d78ffe61d0f1d46c3dd79ace8e3a 100644 --- a/core/modules/comment/src/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php @@ -265,8 +265,8 @@ function testCommentFunctionality() { // Test that field to change cardinality is not available. $this->drupalGet('entity_test/structure/entity_test/fields/entity_test.entity_test.comment/storage'); $this->assertResponse(200); - $this->assertNoField('field_storage[cardinality_number]'); - $this->assertNoField('field_storage[cardinality]'); + $this->assertNoField('cardinality_number'); + $this->assertNoField('cardinality'); $this->drupalLogin($this->adminUser); @@ -413,7 +413,7 @@ function testCommentFunctionality() { // Add a new comment field. $storage_edit = array( - 'field_storage[settings][comment_type]' => 'foobar', + 'settings[comment_type]' => 'foobar', ); $this->fieldUIAddNewField('entity_test/structure/entity_test', 'foobar', 'Foobar', 'comment', $storage_edit); diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php index e6718c0d362c29082f659717f7d8a32d77564a3e..0040284f43f1fdf1e894a7207f7d3e71eafb05df 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php @@ -75,10 +75,10 @@ public function testFieldAdminHandler() { ), t('Save and continue')); // Node should be selected by default. - $this->assertFieldByName('field_storage[settings][target_type]', 'node'); + $this->assertFieldByName('settings[target_type]', 'node'); // Check that all entity types can be referenced. - $this->assertFieldSelectOptions('field_storage[settings][target_type]', array_keys(\Drupal::entityManager()->getDefinitions())); + $this->assertFieldSelectOptions('settings[target_type]', array_keys(\Drupal::entityManager()->getDefinitions())); // Second step: 'Field settings' form. $this->drupalPostForm(NULL, array(), t('Save field settings')); @@ -133,7 +133,7 @@ public function testFieldAdminHandler() { // specific to its selection handler are displayed. $field_name = 'node.' . $this->type . '.field_test'; $edit = array( - 'field_storage[settings][target_type]' => 'taxonomy_term', + 'settings[target_type]' => 'taxonomy_term', ); $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); $this->drupalGet($bundle_path . '/fields/' . $field_name); @@ -143,7 +143,7 @@ public function testFieldAdminHandler() { // its selection handler are displayed. $field_name = 'node.' . $this->type . '.field_test'; $edit = array( - 'field_storage[settings][target_type]' => 'user', + 'settings[target_type]' => 'user', ); $this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings')); $this->drupalGet($bundle_path . '/fields/' . $field_name); @@ -240,7 +240,7 @@ public function createEntityReferenceField($target_type, $bundle = NULL) { $field_name = strtolower($this->randomMachineName()); $storage_edit = $field_edit = array(); - $storage_edit['field_storage[settings][target_type]'] = $target_type; + $storage_edit['settings[target_type]'] = $target_type; if ($bundle) { $field_edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE; } diff --git a/core/modules/field_ui/field_ui.module b/core/modules/field_ui/field_ui.module index 5c2e22f604d94cd44456b6664bb80eb2e6d36743..20996cde44c832e32b4fbe3894ecda9ddf37be5c 100644 --- a/core/modules/field_ui/field_ui.module +++ b/core/modules/field_ui/field_ui.module @@ -68,8 +68,11 @@ function field_ui_entity_type_build(array &$entity_types) { /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */ $entity_types['field_config']->setFormClass('delete', 'Drupal\field_ui\Form\FieldConfigDeleteForm'); $entity_types['field_config']->setListBuilderClass('Drupal\field_ui\FieldConfigListBuilder'); + + $entity_types['field_storage_config']->setFormClass('edit', 'Drupal\field_ui\Form\FieldStorageConfigEditForm'); $entity_types['field_storage_config']->setListBuilderClass('Drupal\field_ui\FieldStorageConfigListBuilder'); $entity_types['field_storage_config']->setLinkTemplate('collection', '/admin/reports/fields'); + $entity_types['entity_form_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityFormDisplayEditForm'); $entity_types['entity_view_display']->setFormClass('edit', 'Drupal\field_ui\Form\EntityViewDisplayEditForm'); } diff --git a/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php new file mode 100644 index 0000000000000000000000000000000000000000..58c4ea9030d856b71874a3ad602e74f0802cba8c --- /dev/null +++ b/core/modules/field_ui/src/Form/FieldStorageConfigEditForm.php @@ -0,0 +1,192 @@ +<?php + +/** + * @file + * Contains \Drupal\field_ui\Form\FieldStorageConfigEditForm. + */ + +namespace Drupal\field_ui\Form; + +use Drupal\Core\Entity\EntityForm; +use Drupal\Core\Field\FieldStorageDefinitionInterface; +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\field\Entity\FieldConfig; +use Drupal\field_ui\FieldUI; + +/** + * Provides a form for the "field storage" edit page. + */ +class FieldStorageConfigEditForm extends EntityForm { + + /** + * The entity being used by this form. + * + * @var \Drupal\field\FieldStorageConfigInterface + */ + protected $entity; + + /** + * {@inheritdoc} + */ + public function getEntityFromRouteMatch(RouteMatchInterface $route_match, $entity_type_id) { + // The URL of this entity form contains only the ID of the field_config + // but we are actually editing a field_storage_config entity. + $field_config = FieldConfig::load($route_match->getRawParameter('field_config')); + + return $field_config->getFieldStorageDefinition(); + } + + /** + * {@inheritdoc} + * + * @param string $field_config + * The ID of the field config whose field storage config is being edited. + */ + public function buildForm(array $form, FormStateInterface $form_state, $field_config = NULL) { + if ($field_config) { + $field = FieldConfig::load($field_config); + $form_state->set('field_config', $field); + + $form_state->set('entity_type_id', $field->getTargetEntityTypeId()); + $form_state->set('bundle', $field->getTargetBundle()); + } + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function form(array $form, FormStateInterface $form_state) { + $form = parent::form($form, $form_state); + + $field_label = $form_state->get('field_config')->label(); + $form['#title'] = $field_label; + $form['#prefix'] = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $field_label)) . '</p>'; + + // See if data already exists for this field. + // If so, prevent changes to the field settings. + if ($this->entity->hasData()) { + $form['#prefix'] = '<div class="messages messages--error">' . $this->t('There is data for this field in the database. The field settings can no longer be changed.') . '</div>' . $form['#prefix']; + } + + // Add settings provided by the field module. The field module is + // responsible for not returning settings that cannot be changed if + // the field already has data. + $form['settings'] = array( + '#weight' => -10, + '#tree' => TRUE, + ); + // Create an arbitrary entity object, so that we can have an instantiated + // FieldItem. + $ids = (object) array( + 'entity_type' => $form_state->get('entity_type_id'), + 'bundle' => $form_state->get('bundle'), + 'entity_id' => NULL + ); + $entity = _field_create_entity_from_ids($ids); + $items = $entity->get($this->entity->getName()); + $item = $items->first() ?: $items->appendItem(); + $form['settings'] += $item->storageSettingsForm($form, $form_state, $this->entity->hasData()); + + // Build the configurable field values. + $cardinality = $this->entity->getCardinality(); + $form['cardinality_container'] = array( + // Reset #parents so the additional container does not appear. + '#parents' => array(), + '#type' => 'fieldset', + '#title' => $this->t('Allowed number of values'), + '#attributes' => array('class' => array( + 'container-inline', + 'fieldgroup', + 'form-composite' + )), + ); + $form['cardinality_container']['cardinality'] = array( + '#type' => 'select', + '#title' => $this->t('Allowed number of values'), + '#title_display' => 'invisible', + '#options' => array( + 'number' => $this->t('Limited'), + FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'), + ), + '#default_value' => ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 'number', + ); + $form['cardinality_container']['cardinality_number'] = array( + '#type' => 'number', + '#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1, + '#min' => 1, + '#title' => $this->t('Limit'), + '#title_display' => 'invisible', + '#size' => 2, + '#states' => array( + 'visible' => array( + ':input[name="cardinality"]' => array('value' => 'number'), + ), + 'disabled' => array( + ':input[name="cardinality"]' => array('value' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), + ), + ), + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + protected function actions(array $form, FormStateInterface $form_state) { + $elements = parent::actions($form, $form_state); + $elements['submit']['#value'] = $this->t('Save field settings'); + + return $elements; + } + + /** + * {@inheritdoc} + */ + public function validate(array $form, FormStateInterface $form_state) { + parent::validate($form, $form_state); + + // Validate field cardinality. + if ($form_state->getValue('cardinality') === 'number' && !$form_state->getValue('cardinality_number')) { + $form_state->setErrorByName('cardinality_number', $this->t('Number of values is required.')); + } + } + + /** + * {@inheritdoc} + */ + public function buildEntity(array $form, FormStateInterface $form_state) { + // Save field cardinality. + if ($form_state->getValue('cardinality') === 'number' && $form_state->getValue('cardinality_number')) { + $form_state->setValue('cardinality', $form_state->getValue('cardinality_number')); + } + + return parent::buildEntity($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function save(array $form, FormStateInterface $form_state) { + $field_label = $form_state->get('field_config')->label(); + try { + $this->entity->save(); + drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $field_label))); + $request = $this->getRequest(); + if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) { + $request->query->remove('destinations'); + $form_state->setRedirectUrl($next_destination); + } + else { + $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($form_state->get('entity_type_id'), $form_state->get('bundle'))); + } + } + catch (\Exception $e) { + drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $field_label, '%message' => $e->getMessage())), 'error'); + } + } + +} diff --git a/core/modules/field_ui/src/Form/FieldStorageEditForm.php b/core/modules/field_ui/src/Form/FieldStorageEditForm.php deleted file mode 100644 index 92ddca16f29609a57cfab4a7eb0ac22a27d5c9d3..0000000000000000000000000000000000000000 --- a/core/modules/field_ui/src/Form/FieldStorageEditForm.php +++ /dev/null @@ -1,223 +0,0 @@ -<?php - -/** - * @file - * Contains \Drupal\field_ui\Form\FieldStorageEditForm. - */ - -namespace Drupal\field_ui\Form; - -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Field\FieldStorageDefinitionInterface; -use Drupal\Core\Form\FormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\TypedData\TypedDataManager; -use Drupal\field\FieldConfigInterface; -use Drupal\field_ui\FieldUI; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Provides a form for the "field storage" edit page. - */ -class FieldStorageEditForm extends FormBase { - - /** - * The field being edited. - * - * @var \Drupal\field\FieldConfigInterface - */ - protected $field; - - /** - * The entity manager. - * - * @var \Drupal\Core\Entity\EntityManagerInterface - */ - protected $entityManager; - - /** - * The typed data manager. - * - * @var \Drupal\Core\TypedData\TypedDataManager - */ - protected $typedDataManager; - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'field_ui_field_storage_edit_form'; - } - - /** - * Constructs a new FieldStorageEditForm object. - * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager. - * @param \Drupal\Core\TypedData\TypedDataManager $typed_data_manager - * The typed data manager. - */ - public function __construct(EntityManagerInterface $entity_manager, TypedDataManager $typed_data_manager) { - $this->entityManager = $entity_manager; - $this->typedDataManager = $typed_data_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('entity.manager'), - $container->get('typed_data_manager') - ); - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state, FieldConfigInterface $field_config = NULL) { - $this->field = $field_config; - $form_state->set('field', $field_config); - $form['#title'] = $this->field->label(); - - $field_storage = $this->field->getFieldStorageDefinition(); - $form['#field'] = $field_storage; - $form['#bundle'] = $this->field->bundle; - - $description = '<p>' . $this->t('These settings apply to the %field field everywhere it is used. These settings impact the way that data is stored in the database and cannot be changed once data has been created.', array('%field' => $this->field->label())) . '</p>'; - - // Create a form structure for the field values. - $form['field_storage'] = array( - '#prefix' => $description, - '#tree' => TRUE, - ); - - // See if data already exists for this field. - // If so, prevent changes to the field settings. - if ($field_storage->hasData()) { - $form['field_storage']['#prefix'] = '<div class="messages messages--error">' . $this->t('There is data for this field in the database. The field settings can no longer be changed.') . '</div>' . $form['field_storage']['#prefix']; - } - - // Add settings provided by the field module. The field module is - // responsible for not returning settings that cannot be changed if - // the field already has data. - $form['field_storage']['settings'] = array( - '#weight' => -10, - ); - // Create an arbitrary entity object, so that we can have an instantiated - // FieldItem. - $ids = (object) array('entity_type' => $this->field->entity_type, 'bundle' => $this->field->bundle, 'entity_id' => NULL); - $entity = _field_create_entity_from_ids($ids); - $items = $entity->get($field_storage->getName()); - $item = $items->first() ?: $items->appendItem(); - $form['field_storage']['settings'] += $item->storageSettingsForm($form, $form_state, $field_storage->hasData()); - - // Build the configurable field values. - $cardinality = $field_storage->getCardinality(); - $form['field_storage']['cardinality_container'] = array( - // Reset #parents to 'field_storage', so the additional container does not appear. - '#parents' => array('field_storage'), - '#type' => 'fieldset', - '#title' => $this->t('Allowed number of values'), - '#attributes' => array('class' => array( - 'container-inline', - 'fieldgroup', - 'form-composite' - )), - ); - $form['field_storage']['cardinality_container']['cardinality'] = array( - '#type' => 'select', - '#title' => $this->t('Allowed number of values'), - '#title_display' => 'invisible', - '#options' => array( - 'number' => $this->t('Limited'), - FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED => $this->t('Unlimited'), - ), - '#default_value' => ($cardinality == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) ? FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED : 'number', - ); - $form['field_storage']['cardinality_container']['cardinality_number'] = array( - '#type' => 'number', - '#default_value' => $cardinality != FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED ? $cardinality : 1, - '#min' => 1, - '#title' => $this->t('Limit'), - '#title_display' => 'invisible', - '#size' => 2, - '#states' => array( - 'visible' => array( - ':input[name="field_storage[cardinality]"]' => array('value' => 'number'), - ), - 'disabled' => array( - ':input[name="field_storage[cardinality]"]' => array('value' => -1), - ), - ), - ); - - // Build the non-configurable field values. - $form['field_storage']['field_name'] = array('#type' => 'value', '#value' => $field_storage->getName()); - $form['field_storage']['type'] = array('#type' => 'value', '#value' => $field_storage->getType()); - $form['field_storage']['module'] = array('#type' => 'value', '#value' => $field_storage->getTypeProvider()); - $form['field_storage']['translatable'] = array('#type' => 'value', '#value' => $field_storage->isTranslatable()); - - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => $this->t('Save field settings'), - '#button_type' => 'primary', - ); - return $form; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - // Validate field cardinality. - $field_values = $form_state->getValue('field_storage'); - $cardinality = $field_values['cardinality']; - $cardinality_number = $field_values['cardinality_number']; - if ($cardinality === 'number' && empty($cardinality_number)) { - $form_state->setErrorByName('field][cardinality_number', $this->t('Number of values is required.')); - } - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $form_values = $form_state->getValues(); - $field_values = $form_values['field_storage']; - - // Save field cardinality. - $cardinality = $field_values['cardinality']; - $cardinality_number = $field_values['cardinality_number']; - if ($cardinality === 'number') { - $cardinality = $cardinality_number; - } - $field_values['cardinality'] = $cardinality; - unset($field_values['container']); - - // Merge incoming form values into the existing field. - $field_storage = $this->field->getFieldStorageDefinition(); - foreach ($field_values as $key => $value) { - $field_storage->set($key, $value); - } - - // Update the field. - try { - $field_storage->save(); - drupal_set_message($this->t('Updated field %label field settings.', array('%label' => $this->field->label()))); - $request = $this->getRequest(); - if (($destinations = $request->query->get('destinations')) && $next_destination = FieldUI::getNextDestination($destinations)) { - $request->query->remove('destinations'); - $form_state->setRedirectUrl($next_destination); - } - else { - $form_state->setRedirectUrl(FieldUI::getOverviewRouteInfo($this->field->entity_type, $this->field->bundle)); - } - } - catch (\Exception $e) { - drupal_set_message($this->t('Attempt to update field %label failed: %message.', array('%label' => $this->field->label(), '%message' => $e->getMessage())), 'error'); - } - } - -} diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 090402709dc47f19156713719d0a8fc7b4c6dcca..84d725bdd2d0c12313aa6458f6e35f3114f2acfb 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -79,8 +79,8 @@ protected function alterRoutes(RouteCollection $collection) { $route = new Route( "$path/fields/{field_config}/storage", - array('_form' => '\Drupal\field_ui\Form\FieldStorageEditForm') + $defaults, - array('_entity_access' => 'field_config.update'), + array('_entity_form' => 'field_storage_config.edit') + $defaults, + array('_permission' => 'administer ' . $entity_type_id . ' fields'), $options ); $collection->add("entity.field_config.{$entity_type_id}_storage_edit_form", $route); diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index befc212995728a2343365952a02e80a19ca9a1ae..e94118b08e18adac0966eb5e77e54c62186d9fd8 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -194,7 +194,7 @@ function updateField() { // Populate the field settings with new settings. $string = 'updated dummy test string'; $edit = array( - 'field_storage[settings][test_field_storage_setting]' => $string, + 'settings[test_field_storage_setting]' => $string, ); $this->drupalPostForm(NULL, $edit, t('Save field settings')); @@ -243,22 +243,22 @@ function cardinalitySettings() { // Assert the cardinality other field cannot be empty when cardinality is // set to 'number'. $edit = array( - 'field_storage[cardinality]' => 'number', - 'field_storage[cardinality_number]' => '', + 'cardinality' => 'number', + 'cardinality_number' => '', ); $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); $this->assertText('Number of values is required.'); // Submit a custom number. $edit = array( - 'field_storage[cardinality]' => 'number', - 'field_storage[cardinality_number]' => 6, + 'cardinality' => 'number', + 'cardinality_number' => 6, ); $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); $this->assertText('Updated field Body field settings.'); $this->drupalGet($field_edit_path); - $this->assertFieldByXPath("//select[@name='field_storage[cardinality]']", 'number'); - $this->assertFieldByXPath("//input[@name='field_storage[cardinality_number]']", 6); + $this->assertFieldByXPath("//select[@name='cardinality']", 'number'); + $this->assertFieldByXPath("//input[@name='cardinality_number']", 6); // Check that tabs displayed. $this->assertLink(t('Edit')); @@ -268,13 +268,13 @@ function cardinalitySettings() { // Set to unlimited. $edit = array( - 'field_storage[cardinality]' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, + 'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, ); $this->drupalPostForm($field_edit_path, $edit, t('Save field settings')); $this->assertText('Updated field Body field settings.'); $this->drupalGet($field_edit_path); - $this->assertFieldByXPath("//select[@name='field_storage[cardinality]']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); - $this->assertFieldByXPath("//input[@name='field_storage[cardinality_number]']", 1); + $this->assertFieldByXPath("//select[@name='cardinality']", FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED); + $this->assertFieldByXPath("//input[@name='cardinality_number']", 1); } /** diff --git a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php index 6677db267cf493f519ae5f4a1b7851e381132db6..56804af673824d2e1c1ead2ba7a6bc33bb030788 100644 --- a/core/modules/file/src/Plugin/Field/FieldType/FileItem.php +++ b/core/modules/file/src/Plugin/Field/FieldType/FileItem.php @@ -128,7 +128,7 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state '#description' => t('This setting only has an effect if the display option is enabled.'), '#states' => array( 'visible' => array( - ':input[name="field_storage[settings][display_field]"]' => array('checked' => TRUE), + ':input[name="settings[display_field]"]' => array('checked' => TRUE), ), ), ); diff --git a/core/modules/file/src/Tests/FileFieldWidgetTest.php b/core/modules/file/src/Tests/FileFieldWidgetTest.php index 8ebb6962c9b931795d16fc27dee86948d397dc9c..5cd74b81c6b66401137bd4bdf85c40e916fe190d 100644 --- a/core/modules/file/src/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/src/Tests/FileFieldWidgetTest.php @@ -232,7 +232,7 @@ function testPrivateFileSetting() { $test_file = $this->getTestFile('text'); // Change the field setting to make its files private, and upload a file. - $edit = array('field_storage[settings][uri_scheme]' => 'private'); + $edit = array('settings[uri_scheme]' => 'private'); $this->drupalPostForm("admin/structure/types/manage/$type_name/fields/$field->id/storage", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node_storage->resetCache(array($nid)); @@ -247,12 +247,12 @@ function testPrivateFileSetting() { // Ensure we can't change 'uri_scheme' field settings while there are some // entities with uploaded files. $this->drupalGet("admin/structure/types/manage/$type_name/fields/$field->id/storage"); - $this->assertFieldByXpath('//input[@id="edit-field-storage-settings-uri-scheme-public" and @disabled="disabled"]', 'public', 'Upload destination setting disabled.'); + $this->assertFieldByXpath('//input[@id="edit-settings-uri-scheme-public" and @disabled="disabled"]', 'public', 'Upload destination setting disabled.'); // Delete node and confirm that setting could be changed. $node->delete(); $this->drupalGet("admin/structure/types/manage/$type_name/fields/$field->id/storage"); - $this->assertFieldByXpath('//input[@id="edit-field-storage-settings-uri-scheme-public" and not(@disabled)]', 'public', 'Upload destination setting enabled.'); + $this->assertFieldByXpath('//input[@id="edit-settings-uri-scheme-public" and not(@disabled)]', 'public', 'Upload destination setting enabled.'); } /** @@ -275,7 +275,7 @@ function testPrivateFileComment() { $name = strtolower($this->randomMachineName()); $label = $this->randomMachineName(); - $storage_edit = array('field_storage[settings][uri_scheme]' => 'private'); + $storage_edit = array('settings[uri_scheme]' => 'private'); $this->fieldUIAddNewField('admin/structure/comment/manage/comment', $name, $label, 'file', $storage_edit); // Manually clear cache on the tester side. diff --git a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php index 6efc84d174601aad744791e1252cdaf7ce5046d1..607ad7dbe15c759d179e215eb28155e9220ce5be 100644 --- a/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php +++ b/core/modules/image/src/Tests/ImageFieldDefaultImagesTest.php @@ -110,7 +110,7 @@ public function testDefaultImages() { $field_id = $field->id(); $this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage"); $this->assertFieldByXpath( - '//input[@name="field_storage[settings][default_image][uuid][fids]"]', + '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), format_string( 'Article image field default equals expected file ID of @fid.', @@ -131,7 +131,7 @@ public function testDefaultImages() { // Confirm the defaults are present on the page field settings form. $this->drupalGet("admin/structure/types/manage/page/fields/$field_id/storage"); $this->assertFieldByXpath( - '//input[@name="field_storage[settings][default_image][uuid][fids]"]', + '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field']->id(), format_string( 'Page image field default equals expected file ID of @fid.', @@ -183,7 +183,7 @@ public function testDefaultImages() { // Confirm that the new default is used on the article field settings form. $this->drupalGet("admin/structure/types/manage/article/fields/$field_id/storage"); $this->assertFieldByXpath( - '//input[@name="field_storage[settings][default_image][uuid][fids]"]', + '//input[@name="settings[default_image][uuid][fids]"]', $default_images['field_new']->id(), format_string( 'Updated image field default equals expected file ID of @fid.', diff --git a/core/modules/image/src/Tests/ImageFieldDisplayTest.php b/core/modules/image/src/Tests/ImageFieldDisplayTest.php index 29fbce398b860a8e1b4603141318f752f3bf769d..a5ac34aae5afb0ab3d25e8f2a53dfd91387219db 100644 --- a/core/modules/image/src/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/src/Tests/ImageFieldDisplayTest.php @@ -297,7 +297,7 @@ function testImageFieldSettings() { // 1, so we need to make sure the file widget prevents these notices by // providing all settings, even if they are not used. // @see FileWidget::formMultipleElements(). - $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', array('field_storage[cardinality]' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings')); + $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $field_name . '/storage', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED), t('Save field settings')); $edit = array( 'files[' . $field_name . '_1][]' => drupal_realpath($test_image->uri), ); @@ -340,9 +340,9 @@ function testImageFieldDefaultImage() { $alt = $this->randomString(512); $title = $this->randomString(1024); $edit = array( - 'files[field_storage_settings_default_image_uuid]' => drupal_realpath($images[0]->uri), - 'field_storage[settings][default_image][alt]' => $alt, - 'field_storage[settings][default_image][title]' => $title, + 'files[settings_default_image_uuid]' => drupal_realpath($images[0]->uri), + 'settings[default_image][alt]' => $alt, + 'settings[default_image][title]' => $title, ); $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.$field_name/storage", $edit, t('Save field settings')); // Clear field definition cache so the new default image is detected. @@ -390,7 +390,7 @@ function testImageFieldDefaultImage() { // Remove default image from the field and make sure it is no longer used. $edit = array( - 'field_storage[settings][default_image][uuid][fids]' => 0, + 'settings[default_image][uuid][fids]' => 0, ); $this->drupalPostForm("admin/structure/types/manage/article/fields/node.article.$field_name/storage", $edit, t('Save field settings')); // Clear field definition cache so the new default image is detected. @@ -404,9 +404,9 @@ function testImageFieldDefaultImage() { $this->createImageField($private_field_name, 'article', array('uri_scheme' => 'private')); // Add a default image to the new field. $edit = array( - 'files[field_storage_settings_default_image_uuid]' => drupal_realpath($images[1]->uri), - 'field_storage[settings][default_image][alt]' => $alt, - 'field_storage[settings][default_image][title]' => $title, + 'files[settings_default_image_uuid]' => drupal_realpath($images[1]->uri), + 'settings[default_image][alt]' => $alt, + 'settings[default_image][title]' => $title, ); $this->drupalPostForm('admin/structure/types/manage/article/fields/node.article.' . $private_field_name . '/storage', $edit, t('Save field settings')); // Clear field definition cache so the new default image is detected. diff --git a/core/modules/options/src/Tests/OptionsFieldUITest.php b/core/modules/options/src/Tests/OptionsFieldUITest.php index ef2b020b95f28165b0e2f288707c468b1327f8b8..c0ab0df2577efee6f56622a3f79fd0b3cbb6fca8 100644 --- a/core/modules/options/src/Tests/OptionsFieldUITest.php +++ b/core/modules/options/src/Tests/OptionsFieldUITest.php @@ -296,7 +296,7 @@ protected function createOptionsField($type) { * Message to display. */ function assertAllowedValuesInput($input_string, $result, $message) { - $edit = array('field_storage[settings][allowed_values]' => $input_string); + $edit = array('settings[allowed_values]' => $input_string); $this->drupalPostForm($this->adminPath, $edit, t('Save field settings')); $this->assertNoRaw('&lt;', 'The page does not have double escaped HTML tags.'); @@ -320,7 +320,7 @@ function testNodeDisplay() { $on = $this->randomMachineName(); $off = $this->randomMachineName(); $edit = array( - 'field_storage[settings][allowed_values]' => + 'settings[allowed_values]' => "1|$on 0|$off", ); diff --git a/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php b/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php index 0f8414f5eae135234de4dc42d20e750b9ebeda53..5be5840bedf03a317230de22bdf2b1806320e85f 100644 --- a/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php +++ b/core/modules/options/src/Tests/OptionsFloatFieldImportTest.php @@ -52,7 +52,7 @@ public function testImport() { $this->copyConfig($this->container->get('config.storage'), $this->container->get('config.storage.staging')); // Set the active to not use dots in the allowed values key names. - $edit = array('field_storage[settings][allowed_values]' => "0|Zero\n1|One"); + $edit = array('settings[allowed_values]' => "0|Zero\n1|One"); $this->drupalPostForm($admin_path, $edit, t('Save field settings')); $field_storage = FieldStorageConfig::loadByName('node', $field_name); $this->assertIdentical($field_storage->getSetting('allowed_values'), $array = array('0' => 'Zero', '1' => 'One'));