diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module index 820d8e6..eb81824 100644 --- a/core/modules/comment/comment.module +++ b/core/modules/comment/comment.module @@ -315,14 +315,12 @@ function comment_view_multiple($comments, $view_mode = 'full', $langcode = NULL) */ function comment_form_field_ui_field_storage_add_form_alter(&$form, FormStateInterface $form_state) { $request = \Drupal::request(); - if ($form['#entity_type_id'] == 'comment' && $request->attributes->has('commented_entity_type')) { + if ($form_state->get('entity_type_id') == 'comment' && $request->attributes->has('commented_entity_type')) { $form['#title'] = \Drupal::service('comment.manager')->getFieldUIPageTitle($request->attributes->get('commented_entity_type'), $request->attributes->get('field_name')); } - if (!_comment_entity_uses_integer_id($form['#entity_type_id'])) { + if (!_comment_entity_uses_integer_id($form_state->get('entity_type_id'))) { // You cannot use comment fields on entity types with non-integer IDs. - // @todo This looks very brittle, we should implement hook_field_presave() - // instead. - unset($form['field']['type']['#options']['comment']); + unset($form['add']['new_field_type']['#options']['comment']); } } diff --git a/core/modules/comment/src/Tests/CommentNonNodeTest.php b/core/modules/comment/src/Tests/CommentNonNodeTest.php index 01fd2a7..b2f22e0 100644 --- a/core/modules/comment/src/Tests/CommentNonNodeTest.php +++ b/core/modules/comment/src/Tests/CommentNonNodeTest.php @@ -409,11 +409,11 @@ public function testsNonIntegerIdEntities() { )); $this->drupalLogin($limited_user); // Visit the Field UI field add page. - $this->drupalGet('entity_test_string_id/structure/entity_test/add-field'); + $this->drupalGet('entity_test_string_id/structure/entity_test/fields/add-field'); // Ensure field isn't shown for string IDs. - $this->assertNoOption('edit-type', 'comment'); + $this->assertNoOption('edit-new-field-type', 'comment'); // Ensure a core field type shown. - $this->assertOption('edit-type', 'boolean'); + $this->assertOption('edit-new-field-type', 'boolean'); // Create a bundle for entity_test_no_id. entity_test_create_bundle('entity_test', 'Entity Test', 'entity_test_no_id'); @@ -421,11 +421,11 @@ public function testsNonIntegerIdEntities() { 'administer entity_test_no_id fields', ))); // Visit the Field UI field add page. - $this->drupalGet('entity_test_no_id/structure/entity_test/add-field'); + $this->drupalGet('entity_test_no_id/structure/entity_test/fields/add-field'); // Ensure field isn't shown for empty IDs. - $this->assertNoOption('edit-type', 'comment'); + $this->assertNoOption('edit-new-field-type', 'comment'); // Ensure a core field type shown. - $this->assertOption('edit-type', 'boolean'); + $this->assertOption('edit-new-field-type', 'boolean'); } } diff --git a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php index f0896e9..278de0d 100644 --- a/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php +++ b/core/modules/entity_reference/src/Tests/EntityReferenceAdminTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\field_ui\Tests\FieldUiTestTrait; use Drupal\simpletest\WebTestBase; use Drupal\taxonomy\Entity\Vocabulary; @@ -17,6 +18,8 @@ */ class EntityReferenceAdminTest extends WebTestBase { + use FieldUiTestTrait; + /** * Modules to install. * @@ -55,10 +58,10 @@ public function testFieldAdminHandler() { $bundle_path = 'admin/structure/types/manage/' . $this->type; // First step: 'Add new field' on the 'Manage fields' page. - $this->drupalPostForm($bundle_path . '/add-field', array( + $this->drupalPostForm($bundle_path . '/fields/add-field', array( 'label' => 'Test label', 'field_name' => 'test', - 'type' => 'entity_reference', + 'new_field_type' => 'entity_reference', ), t('Save and continue')); // Node should be selected by default. @@ -191,24 +194,13 @@ public function createEntityReferenceField($target_type, $bundle = NULL) { // Generate a random field name, must be only lowercase characters. $field_name = strtolower($this->randomMachineName()); - // Create the initial entity reference. - $this->drupalPostForm($bundle_path . '/add-field', array( - 'label' => $this->randomMachineName(), - 'field_name' => $field_name, - 'type' => 'entity_reference', - ), t('Save and continue')); - - // Select the correct target type given in the parameters and save field settings. - $this->drupalPostForm(NULL, array('field_storage[settings][target_type]' => $target_type), t('Save field settings')); - - // Select required fields if there are any. - $edit = array(); - if($bundle) { - $edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE; + $storage_edit = $field_edit = array(); + $storage_edit['field_storage[settings][target_type]'] = $target_type; + if ($bundle) { + $field_edit['field[settings][handler_settings][target_bundles][' . $bundle . ']'] = TRUE; } - // Save settings. - $this->drupalPostForm(NULL, $edit, t('Save settings')); + $this->fieldUIAddNewField($bundle_path, $field_name, NULL, 'entity_reference', $storage_edit, $field_edit); // Returns the generated field name. return $field_name; diff --git a/core/modules/field_ui/css/field_ui.admin.css b/core/modules/field_ui/css/field_ui.admin.css index ede3d06..f85e101 100644 --- a/core/modules/field_ui/css/field_ui.admin.css +++ b/core/modules/field_ui/css/field_ui.admin.css @@ -9,41 +9,22 @@ margin-right: 1em; vertical-align: text-bottom; } -.field-ui-field-storage-add-form .field-type-wrapper .form-type-item { +[dir="rtl"] .field-ui-field-storage-add-form .field-type-wrapper .form-item { + float: right; + margin-left: 1em; + margin-right: 0; +} +.field-ui-field-storage-add-form .field-type-wrapper .form-item-separator { margin-top: 2.3em; } /* 'Manage fields' and 'Manage display' overviews */ -.field-ui-overview .add-new .label-input { - float: left; /* LTR */ -} -[dir="rtl"] .field-ui-overview .add-new .label-input { - float: right; -} -.field-ui-overview .add-new .description { - margin-bottom: 0; - max-width: 250px; -} -.field-ui-overview .add-new .form-type-machine-name .description { - white-space: normal; -} -.field-ui-overview .add-new .add-new-placeholder { - font-weight: bold; - padding-bottom: .5em; -} .field-ui-overview .region-title td { font-weight: bold; } .field-ui-overview .region-message td { font-style: italic; } -.field-ui-overview .region-add-new-title { - display: none; -} -.field-ui-overview .add-new td { - vertical-align: top; - white-space: nowrap; -} /* 'Manage form display' and 'Manage display' overview */ .field-ui-overview .field-plugin-summary-cell { diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js index 1d1387f..9acc98f 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -9,50 +9,54 @@ Drupal.behaviors.fieldUIFieldStorageAddForm = { attach: function (context) { - var $fieldType = $(context).find('select[name="type"]'); - var $existingField = $(context).find('select[name="existing_field_name"]'); + var $newFieldType = $(context).find('select[name="new_field_type"]').once('new-field-type'); + var $existingStorageName = $(context).find('select[name="existing_storage_name"]').once('existing-storage-name'); var $fieldLabel = $(context).find('input[name="label"]'); var $machineName = $(context).find('.form-item-label .field-suffix'); var labelValue; // When the user selects a new field type, clear the "existing field" // selection and re-populate the label if we have something in the cache. - $fieldType.change(function () { - if ($(this).val() != '') { - $existingField.val('').change(); - - if (labelValue != null) { - $fieldLabel.val(labelValue).trigger('keyup'); - $machineName.show(); - labelValue = null; + if ($newFieldType.length) { + $newFieldType.change(function () { + if ($(this).val() != '') { + $existingStorageName.val('').change(); + + if (labelValue != null) { + $fieldLabel.val(labelValue).trigger('keyup'); + $machineName.show(); + labelValue = null; + } } - } - }); + }); + } // When the user selects an existing field, clear the "new field type" // selection and populate the 'label' element. - $existingField.change(function (event) { - if ($(this).val() != '') { - // Keep the current label value (if any) in a static cache so we can - // re-use it if the user decides to select a new field type again. - if ($fieldType.val()) { - labelValue = $fieldLabel.val(); + if ($existingStorageName.length) { + $existingStorageName.change(function (event) { + if ($(this).val() != '') { + // Keep the current label value (if any) in a static cache so we can + // re-use it if the user decides to select a new field type again. + if ($newFieldType.val()) { + labelValue = $fieldLabel.val(); + } + + // Reset the field type selection. + $newFieldType.val(''); + + // Pre-populate the label and hide the machine name (field_name). + $fieldLabel.val(drupalSettings.existingFieldLabels[$(this).val()]); + $machineName.hide(); } - - // Reset the field type selection. - $fieldType.val(''); - - // Pre-populate the label and hide the machine name (field_name). - $fieldLabel.val(drupalSettings.existingFieldLabels[$(this).val()]); - $machineName.hide(); - } - // Reset the auto-populated label value if this is a user-initiated - // event (i.e. changing the value of the "existing field" element). - else if (event.originalEvent !== undefined && labelValue == null) { - $fieldLabel.val(''); - $machineName.show(); - } - }); + // Reset the auto-populated label value if this is a user-initiated + // event (i.e. changing the value of the "existing field" element). + else if (event.originalEvent !== undefined && labelValue == null) { + $fieldLabel.val(''); + $machineName.show(); + } + }); + } } }; diff --git a/core/modules/field_ui/src/DisplayOverview.php b/core/modules/field_ui/src/DisplayOverview.php index 96d6a9f..b302529 100644 --- a/core/modules/field_ui/src/DisplayOverview.php +++ b/core/modules/field_ui/src/DisplayOverview.php @@ -204,7 +204,7 @@ protected function getTableHeader() { */ protected function getOverviewRoute($mode) { return Url::fromRoute('field_ui.display_overview_view_mode_' . $this->entity_type, [ - $this->bundleEntityType => $this->bundle, + $this->bundleEntityTypeId => $this->bundle, 'view_mode_name' => $mode, ]); } diff --git a/core/modules/field_ui/src/DisplayOverviewBase.php b/core/modules/field_ui/src/DisplayOverviewBase.php index 050b8e8..09322d3 100644 --- a/core/modules/field_ui/src/DisplayOverviewBase.php +++ b/core/modules/field_ui/src/DisplayOverviewBase.php @@ -42,11 +42,12 @@ protected $bundle = ''; /** - * The entity type of the entity bundle. + * The name of the entity type which provides bundles for the entity type + * defined above. * * @var string */ - protected $bundleEntityType; + protected $bundleEntityTypeId; /** * The entity view or form mode. @@ -186,18 +187,15 @@ protected function getFieldDefinitions() { */ public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL, $mode = 'default') { $entity_type = $this->entityManager->getDefinition($entity_type_id); - $this->bundleEntityType = $entity_type->getBundleEntityType(); - $stored_bundle = $form_state->get('bundle'); - if (!$stored_bundle) { - if (!$bundle) { - $bundle = $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityType); - } - $stored_bundle = $bundle; + $this->bundleEntityTypeId = $entity_type->getBundleEntityType(); + + if (!$form_state->get('bundle')) { + $bundle = $bundle ?: $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId); $form_state->set('bundle', $bundle); } $this->entity_type = $entity_type_id; - $this->bundle = $stored_bundle; + $this->bundle = $form_state->get('bundle'); $this->mode = $mode; $field_definitions = $this->getFieldDefinitions(); diff --git a/core/modules/field_ui/src/FieldConfigListBuilder.php b/core/modules/field_ui/src/FieldConfigListBuilder.php index f0290ea..ea5170f 100644 --- a/core/modules/field_ui/src/FieldConfigListBuilder.php +++ b/core/modules/field_ui/src/FieldConfigListBuilder.php @@ -38,25 +38,18 @@ class FieldConfigListBuilder extends ConfigEntityListBuilder { protected $targetBundle; /** - * The entity type of the target entity bundle. - * - * @var string - */ - protected $targetBundleEntityType; - - /** - * An array of field type definitions. + * The entity manager. * - * @var array + * @var \Drupal\Core\Entity\EntityManagerInterface */ - protected $fieldTypes; + protected $entityManager; /** - * The entity manager. + * The field type plugin manager. * - * @var \Drupal\Core\Entity\EntityManagerInterface + * @var \Drupal\Core\Field\FieldTypePluginManagerInterface */ - protected $entityManager; + protected $fieldTypeManager; /** * Constructs a new class instance. @@ -88,8 +81,6 @@ public static function createInstance(ContainerInterface $container, EntityTypeI public function render($target_entity_type_id = NULL, $target_bundle = NULL) { $this->targetEntityTypeId = $target_entity_type_id; $this->targetBundle = $target_bundle; - $this->targetBundleEntityType = $this->entityManager->getDefinition($target_entity_type_id)->getBundleEntityType(); - $this->fieldTypes = $this->fieldTypeManager->getDefinitions(); $build = parent::render(); $build['#attributes']['id'] = 'field-overview'; @@ -133,8 +124,9 @@ public function buildHeader() { public function buildRow(EntityInterface $field_config) { /** @var \Drupal\field\FieldConfigInterface $field_config */ $field_storage = $field_config->getFieldStorageDefinition(); + $target_bundle_entity_type_id = $this->entityManager->getDefinition($this->targetEntityTypeId)->getBundleEntityType(); $route_parameters = array( - $this->targetBundleEntityType => $this->targetBundle, + $target_bundle_entity_type_id => $this->targetBundle, 'field_config' => $field_config->id(), ); @@ -146,7 +138,7 @@ public function buildRow(EntityInterface $field_config) { 'field_type' => array( 'data' => array( '#type' => 'link', - '#title' => $this->fieldTypes[$field_storage->getType()]['label'], + '#title' => $this->fieldTypeManager->getDefinitions()[$field_storage->getType()]['label'], '#url' => Url::fromRoute('field_ui.storage_edit_' . $this->targetEntityTypeId, $route_parameters), '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))), ), diff --git a/core/modules/field_ui/src/Form/FieldStorageAddForm.php b/core/modules/field_ui/src/Form/FieldStorageAddForm.php index 25c168f..5a265a4 100644 --- a/core/modules/field_ui/src/Form/FieldStorageAddForm.php +++ b/core/modules/field_ui/src/Form/FieldStorageAddForm.php @@ -38,7 +38,8 @@ class FieldStorageAddForm extends FormBase { protected $bundle; /** - * The entity type of the entity bundle. + * The name of the entity type which provides bundles for the entity type + * defined above. * * @var string */ @@ -116,20 +117,17 @@ public static function create(ContainerInterface $container) { public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $bundle = NULL) { $entity_type = $this->entityManager->getDefinition($entity_type_id); $this->bundleEntityTypeId = $entity_type->getBundleEntityType(); - if (!$form_state->hasValue('bundle')) { - if (!$bundle) { - $bundle = $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId); - } - $form_state->setValue('bundle', $bundle); - } - $this->entityTypeId = $entity_type_id; - $this->bundle = $form_state->getValue('bundle'); + if (!$form_state->get('entity_type_id')) { + $form_state->set('entity_type_id', $entity_type_id); + } + if (!$form_state->get('bundle')) { + $bundle = $bundle ?: $this->getRequest()->attributes->get('_raw_variables')->get($this->bundleEntityTypeId); + $form_state->set('bundle', $bundle); + } - $form += array( - '#entity_type_id' => $this->entityTypeId, - '#bundle' => $this->bundle, - ); + $this->entityTypeId = $form_state->get('entity_type_id'); + $this->bundle = $form_state->get('bundle'); // Gather valid field types. $field_type_options = array(); @@ -141,12 +139,12 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t } asort($field_type_options); - $form['field'] = array( + $form['add'] = array( '#type' => 'container', '#attributes' => array('class' => array('field-type-wrapper', 'clearfix')), ); - $form['field']['type'] = array( + $form['add']['new_field_type'] = array( '#type' => 'select', '#title' => $this->t('Add a new field'), '#options' => $field_type_options, @@ -155,11 +153,11 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t // Re-use existing field. if ($existing_field_storage_options = $this->getExistingFieldStorageOptions()) { - $form['field']['separator'] = array( + $form['add']['separator'] = array( '#type' => 'item', '#markup' => $this->t('or'), ); - $form['field']['existing_field_name'] = array( + $form['add']['existing_storage_name'] = array( '#type' => 'select', '#title' => $this->t('Re-use an existing field'), '#options' => $existing_field_storage_options, @@ -170,7 +168,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t } else { // Provide a placeholder form element to simplify the validation code. - $form['field']['existing_field_name'] = array( + $form['add']['existing_storage_name'] = array( '#type' => 'value', '#value' => FALSE, ); @@ -181,8 +179,8 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t '#type' => 'container', '#states' => array( '!visible' => array( - ':input[name="type"]' => array('value' => ''), - ':input[name="existing_field_name"]' => array('value' => ''), + ':input[name="new_field_type"]' => array('value' => ''), + ':input[name="existing_storage_name"]' => array('value' => ''), ), ), ); @@ -236,13 +234,13 @@ public function buildForm(array $form, FormStateInterface $form_state, $entity_t */ public function validateForm(array &$form, FormStateInterface $form_state) { // Missing field type. - if (!$form_state->getValue('type') && !$form_state->getValue('existing_field_name')) { - $form_state->setErrorByName('type', $this->t('You need to select a field type or an existing field.')); + if (!$form_state->getValue('new_field_type') && !$form_state->getValue('existing_storage_name')) { + $form_state->setErrorByName('new_field_type', $this->t('You need to select a field type or an existing field.')); } // Both field type and existing field option selected. This is prevented in // the UI with JavaScript but we also need a proper server-side validation. - elseif ($form_state->getValue('type') && $form_state->getValue('existing_field_name')) { - $form_state->setErrorByName('type', $this->t('Adding a new field and re-using an existing field at the same time is not allowed.')); + elseif ($form_state->getValue('new_field_type') && $form_state->getValue('existing_storage_name')) { + $form_state->setErrorByName('new_field_type', $this->t('Adding a new field and re-using an existing field at the same time is not allowed.')); return; } @@ -261,17 +259,15 @@ public function validateForm(array &$form, FormStateInterface $form_state) { * @see \Drupal\field_ui\Form\FieldStorageAddForm::validateForm() */ protected function validateAddNew(array $form, FormStateInterface $form_state) { - $field = $form_state->getValues(); - // Validate if any information was provided in the 'add new field' case. - if ($field['type']) { + if ($form_state->getValue('new_field_type')) { // Missing field name. - if (!$field['field_name']) { + if (!$form_state->getValue('field_name')) { $form_state->setErrorByName('field_name', $this->t('Add new field: you need to provide a machine name for the field.')); } // Field name validation. else { - $field_name = $field['field_name']; + $field_name = $form_state->getValue('field_name'); // Add the field prefix. $field_name = $this->configFactory->get('field_ui.settings')->get('field_prefix') . $field_name; @@ -291,7 +287,7 @@ protected function validateAddNew(array $form, FormStateInterface $form_state) { * @see \Drupal\field_ui\Form\FieldStorageAddForm::validateForm() */ protected function validateAddExisting(array $form, FormStateInterface $form_state) { - if ($form_state->getValue('existing_field_name')) { + if ($form_state->getValue('existing_storage_name')) { // Discard any value that might be set for the field name. $form_state->setValueForElement($form['name_wrapper']['field_name'], ''); } @@ -306,27 +302,25 @@ public function submitForm(array &$form, FormStateInterface $form_state) { $destinations = array(); // Create new field. - if ($values['type']) { - $field_storage = array( - 'field_name' => $values['field_name'], - 'entity_type' => $this->entityTypeId, - 'type' => $values['type'], - 'translatable' => $values['translatable'], - ); - $field = array( - 'field_name' => $values['field_name'], - 'entity_type' => $this->entityTypeId, - 'bundle' => $this->bundle, - 'label' => $values['label'], - // Field translatability should be explicitly enabled by the users. - 'translatable' => FALSE, - ); - + if ($values['new_field_type']) { // Create the field storage and field. try { - $this->entityManager->getStorage('field_storage_config')->create($field_storage)->save(); - $new_field = $this->entityManager->getStorage('field_config')->create($field); - $new_field->save(); + $this->entityManager->getStorage('field_storage_config')->create(array( + 'field_name' => $values['field_name'], + 'entity_type' => $this->entityTypeId, + 'type' => $values['new_field_type'], + 'translatable' => $values['translatable'], + ))->save(); + + $field = $this->entityManager->getStorage('field_config')->create(array( + 'field_name' => $values['field_name'], + 'entity_type' => $this->entityTypeId, + 'bundle' => $this->bundle, + 'label' => $values['label'], + // Field translatability should be explicitly enabled by the users. + 'translatable' => FALSE, + )); + $field->save(); $this->configureEntityDisplays($values['field_name']); @@ -334,7 +328,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) { // configured for new fields. $route_parameters = array( $this->bundleEntityTypeId => $this->bundle, - 'field_config' => $new_field->id(), + 'field_config' => $field->id(), ); $destinations[] = array('route_name' => 'field_ui.storage_edit_' . $this->entityTypeId, 'route_parameters' => $route_parameters); $destinations[] = array('route_name' => 'field_ui.field_edit_' . $this->entityTypeId, 'route_parameters' => $route_parameters); @@ -345,40 +339,38 @@ public function submitForm(array &$form, FormStateInterface $form_state) { } catch (\Exception $e) { $error = TRUE; - drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $field['label'], '!message' => $e->getMessage())), 'error'); + drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $values['label'], '!message' => $e->getMessage())), 'error'); } } // Re-use existing field. - if ($values['existing_field_name']) { - $field_name = $values['existing_field_name']; - - $field = array( - 'field_name' => $field_name, - 'entity_type' => $this->entityTypeId, - 'bundle' => $this->bundle, - 'label' => $values['label'], - ); + if ($values['existing_storage_name']) { + $field_name = $values['existing_storage_name']; try { - $new_field = $this->entityManager->getStorage('field_config')->create($field); - $new_field->save(); + $field = $this->entityManager->getStorage('field_config')->create(array( + 'field_name' => $field_name, + 'entity_type' => $this->entityTypeId, + 'bundle' => $this->bundle, + 'label' => $values['label'], + )); + $field->save(); $this->configureEntityDisplays($field_name); $route_parameters = array( $this->bundleEntityTypeId => $this->bundle, - 'field_config' => $new_field->id(), + 'field_config' => $field->id(), ); $destinations[] = array('route_name' => 'field_ui.field_edit_' . $this->entityTypeId, 'route_parameters' => $route_parameters); $destinations[] = array('route_name' => 'field_ui.overview_' . $this->entityTypeId, 'route_parameters' => $route_parameters); // Store new field information for any additional submit handlers. - $form_state->set(['fields_added', '_add_existing_field'], $field['field_name']); + $form_state->set(['fields_added', '_add_existing_field'], $field_name); } catch (\Exception $e) { $error = TRUE; - drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $field['label'], '!message' => $e->getMessage())), 'error'); + drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $values['label'], '!message' => $e->getMessage())), 'error'); } } @@ -498,7 +490,7 @@ protected function getExistingFieldLabels(array $field_names) { */ public function fieldNameExists($value, $element, FormStateInterface $form_state) { // Don't validate the case when an existing field has been selected. - if ($form_state->getValue('existing_field_name')) { + if ($form_state->getValue('existing_storage_name')) { return FALSE; } diff --git a/core/modules/field_ui/src/FormDisplayOverview.php b/core/modules/field_ui/src/FormDisplayOverview.php index 05db56b..1728044 100644 --- a/core/modules/field_ui/src/FormDisplayOverview.php +++ b/core/modules/field_ui/src/FormDisplayOverview.php @@ -169,7 +169,7 @@ protected function getTableHeader() { */ protected function getOverviewRoute($mode) { return Url::fromRoute('field_ui.form_display_overview_form_mode_' . $this->entity_type, [ - $this->bundleEntityType => $this->bundle, + $this->bundleEntityTypeId => $this->bundle, 'form_mode_name' => $mode, ]); } diff --git a/core/modules/field_ui/src/Routing/RouteSubscriber.php b/core/modules/field_ui/src/Routing/RouteSubscriber.php index 51fa63b..5e9c265 100644 --- a/core/modules/field_ui/src/Routing/RouteSubscriber.php +++ b/core/modules/field_ui/src/Routing/RouteSubscriber.php @@ -99,7 +99,7 @@ protected function alterRoutes(RouteCollection $collection) { $collection->add("field_ui.overview_$entity_type_id", $route); $route = new Route( - "$path/add-field", + "$path/fields/add-field", array( '_form' => '\Drupal\field_ui\Form\FieldStorageAddForm', '_title' => 'Add field', diff --git a/core/modules/field_ui/src/Tests/FieldUiTestTrait.php b/core/modules/field_ui/src/Tests/FieldUiTestTrait.php index 6848d3e..a597b97 100644 --- a/core/modules/field_ui/src/Tests/FieldUiTestTrait.php +++ b/core/modules/field_ui/src/Tests/FieldUiTestTrait.php @@ -34,7 +34,7 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $field_type = 'test_field', array $storage_edit = array(), array $field_edit = array()) { $label = $label ?: $this->randomString(); $initial_edit = array( - 'type' => $field_type, + 'new_field_type' => $field_type, 'label' => $label, 'field_name' => $field_name, ); @@ -42,7 +42,7 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi // Allow the caller to set a NULL path in case they navigated to the right // page before calling this method. if ($bundle_path !== NULL) { - $bundle_path = "$bundle_path/add-field"; + $bundle_path = "$bundle_path/fields/add-field"; } // First step: 'Add field' page. @@ -68,7 +68,7 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi * * @param string $bundle_path * Admin path of the bundle that the field is to be attached to. - * @param string $existing_field_name + * @param string $existing_storage_name * The name of the existing field storage for which we want to add a new * field. * @param string $label @@ -77,15 +77,15 @@ public function fieldUIAddNewField($bundle_path, $field_name, $label = NULL, $fi * (optional) $edit parameter for drupalPostForm() on the second step * ('Field settings' form). */ - public function fieldUIAddExistingField($bundle_path, $existing_field_name, $label = NULL, array $field_edit = array()) { + public function fieldUIAddExistingField($bundle_path, $existing_storage_name, $label = NULL, array $field_edit = array()) { $label = $label ?: $this->randomString(); $initial_edit = array( - 'existing_field_name' => $existing_field_name, + 'existing_storage_name' => $existing_storage_name, 'label' => $label, ); // First step: 'Re-use existing field' on the 'Add field' page. - $this->drupalPostForm("$bundle_path/add-field", $initial_edit, t('Save and continue')); + $this->drupalPostForm("$bundle_path/fields/add-field", $initial_edit, t('Save and continue')); $this->assertNoRaw('<', 'The page does not have double escaped HTML tags.'); // Second step: 'Field settings' form. diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index 7e62db2..2e65bda 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -175,14 +175,14 @@ function updateField() { */ function addExistingField() { // Check "Re-use existing field" appears. - $this->drupalGet('admin/structure/types/manage/page/add-field'); + $this->drupalGet('admin/structure/types/manage/page/fields/add-field'); $this->assertRaw(t('Re-use an existing field'), '"Re-use existing field" was found.'); // Check that fields of other entity types (here, the 'comment_body' field) // do not show up in the "Re-use existing field" list. - $this->assertFalse($this->xpath('//select[@id="edit-existing-field-name"]//option[@value="comment"]'), 'The list of options respects entity type restrictions.'); + $this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value="comment"]'), 'The list of options respects entity type restrictions.'); // Validate the FALSE assertion above by also testing a valid one. - $this->assertTrue($this->xpath('//select[@id="edit-existing-field-name"]//option[@value=:field_name]', array(':field_name' => $this->field_name)), 'The list of options shows a valid option.'); + $this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $this->field_name)), 'The list of options shows a valid option.'); // Add a new field based on an existing field. $this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->field_name, $this->field_label . '_2'); @@ -253,7 +253,7 @@ protected function addPersistentFieldStorage() { $this->drupalPostForm(NULL, array(), t('Delete')); } // Check "Re-use existing field" appears. - $this->drupalGet('admin/structure/types/manage/page/add-field'); + $this->drupalGet('admin/structure/types/manage/page/fields/add-field'); $this->assertRaw(t('Re-use an existing field'), '"Re-use existing field" was found.'); // Add a new field for the orphaned storage. $this->fieldUIAddExistingField("admin/structure/types/manage/page", $this->field_name); @@ -298,7 +298,7 @@ function testFieldPrefix() { 'label' => $field_exceed_max_length_label, 'field_name' => $field_exceed_max_length_input, ); - $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/add-field', $edit, t('Save and continue')); + $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/fields/add-field', $edit, t('Save and continue')); $this->assertText('Machine-readable name cannot be longer than 22 characters but is currently 23 characters long.'); // Create a valid field. @@ -409,19 +409,19 @@ function testDisallowedFieldNames() { $label = 'Disallowed field'; $edit = array( 'label' => $label, - 'type' => 'test_field', + 'new_field_type' => 'test_field', ); // Try with an entity key. $edit['field_name'] = 'title'; $bundle_path = 'admin/structure/types/manage/' . $this->type; - $this->drupalPostForm("$bundle_path/add-field", $edit, t('Save and continue')); + $this->drupalPostForm("$bundle_path/fields/add-field", $edit, t('Save and continue')); $this->assertText(t('The machine-readable name is already in use. It must be unique.')); // Try with a base field. $edit['field_name'] = 'sticky'; $bundle_path = 'admin/structure/types/manage/' . $this->type; - $this->drupalPostForm("$bundle_path/add-field", $edit, t('Save and continue')); + $this->drupalPostForm("$bundle_path/fields/add-field", $edit, t('Save and continue')); $this->assertText(t('The machine-readable name is already in use. It must be unique.')); } @@ -467,9 +467,9 @@ function testLockedField() { */ function testHiddenFields() { // Check that the field type is not available in the 'add new field' row. - $this->drupalGet('admin/structure/types/manage/' . $this->type . '/add-field'); - $this->assertFalse($this->xpath('//select[@id="edit-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property."); - $this->assertTrue($this->xpath('//select[@id="edit-type"]//option[@value="shape"]'), "The 'add new field' select shows a valid option."); + $this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/add-field'); + $this->assertFalse($this->xpath('//select[@id="edit-new-field-type"]//option[@value="hidden_test_field"]'), "The 'add new field' select respects field types 'no_ui' property."); + $this->assertTrue($this->xpath('//select[@id="edit-new-field-type"]//option[@value="shape"]'), "The 'add new field' select shows a valid option."); // Create a field storage and a field programmatically. $field_name = 'hidden_test_field'; @@ -497,18 +497,18 @@ function testHiddenFields() { // Check that the field does not appear in the 're-use existing field' row // on other bundles. - $this->drupalGet('admin/structure/types/manage/page/add-field'); - $this->assertFalse($this->xpath('//select[@id="edit-existing-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 're-use existing field' select respects field types 'no_ui' property."); - $this->assertTrue($this->xpath('//select[@id="edit-existing-field-name"]//option[@value=:field_name]', array(':field_name' => 'field_tags')), "The 're-use existing field' select shows a valid option."); + $this->drupalGet('admin/structure/types/manage/page/fields/add-field'); + $this->assertFalse($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 're-use existing field' select respects field types 'no_ui' property."); + $this->assertTrue($this->xpath('//select[@id="edit-existing-storage-name"]//option[@value=:field_name]', array(':field_name' => 'field_tags')), "The 're-use existing field' select shows a valid option."); // Check that non-configurable fields are not available. $field_types = \Drupal::service('plugin.manager.field.field_type')->getDefinitions(); foreach ($field_types as $field_type => $definition) { if (empty($definition['no_ui'])) { - $this->assertTrue($this->xpath('//select[@id="edit-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type))); + $this->assertTrue($this->xpath('//select[@id="edit-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Configurable field type @field_type is available.', array('@field_type' => $field_type))); } else { - $this->assertFalse($this->xpath('//select[@id="edit-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Non-configurable field type @field_type is not available.', array('@field_type' => $field_type))); + $this->assertFalse($this->xpath('//select[@id="edit-new-field-type"]//option[@value=:field_type]', array(':field_type' => $field_type)), String::format('Non-configurable field type @field_type is not available.', array('@field_type' => $field_type))); } } } @@ -535,9 +535,9 @@ function testDuplicateFieldName() { $edit = array( 'field_name' => 'tags', 'label' => $this->randomMachineName(), - 'type' => 'taxonomy_term_reference', + 'new_field_type' => 'taxonomy_term_reference', ); - $url = 'admin/structure/types/manage/' . $this->type . '/add-field'; + $url = 'admin/structure/types/manage/' . $this->type . '/fields/add-field'; $this->drupalPostForm($url, $edit, t('Save and continue')); $this->assertText(t('The machine-readable name is already in use. It must be unique.'));