diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php
index 8069a3f..7ee3401 100644
--- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php
+++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNonNodeTest.php
@@ -356,13 +356,13 @@ function testCommentFunctionality() {
$this->assertNoFieldChecked('edit-default-value-input-comment-0-status-2');
// Add a new comment field.
- $this->drupalGet('admin/structure/entity-test-render/manage/entity_test_render/fields');
+ $this->drupalGet('admin/structure/entity-test-render/manage/entity_test_render/add-field');
$edit = array(
- 'fields[_add_new_field][label]' => 'Foobar',
- 'fields[_add_new_field][field_name]' => 'foobar',
- 'fields[_add_new_field][type]' => 'comment',
+ '_add_new_field[label]' => 'Foobar',
+ '_add_new_field[field_name]' => 'foobar',
+ 'type' => 'comment',
);
- $this->drupalPostForm(NULL, $edit, t('Save'));
+ $this->drupalPostForm(NULL, $edit, t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings'));
$this->assertRaw(t('Saved %name configuration', array('%name' => 'Foobar')));
diff --git a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php
index 1c69c2e..6b5b1fb 100644
--- a/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php
+++ b/core/modules/contact/lib/Drupal/contact/Tests/ContactSitewideTest.php
@@ -225,6 +225,7 @@ function testSiteWideContact() {
// Test field UI and field integration.
$this->drupalGet('admin/structure/contact');
+ // Test the dropdown operations for administering forms.
// Find out in which row the category we want to add a field to is.
$i = 0;
foreach($this->xpath('//table/tbody/tr') as $row) {
@@ -238,13 +239,14 @@ function testSiteWideContact() {
$this->assertResponse(200);
// Create a simple textfield.
+ $this->clickLink(t('Add field'));
+ $this->assertResponse(200);
$edit = array(
- 'fields[_add_new_field][label]' => $field_label = $this->randomName(),
- 'fields[_add_new_field][field_name]' => Unicode::strtolower($this->randomName()),
- 'fields[_add_new_field][type]' => 'text',
+ '_add_new_field[label]' => $field_label = $this->randomString(),
+ '_add_new_field[field_name]' => $name = strtolower($this->randomName()),
+ 'type' => 'text',
);
- $field_name = 'field_' . $edit['fields[_add_new_field][field_name]'];
- $this->drupalPostForm(NULL, $edit, t('Save'));
+ $this->drupalPostForm(NULL, $edit, t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings'));
@@ -253,6 +255,7 @@ function testSiteWideContact() {
$this->assertText($field_label);
// Submit the contact form and verify the content.
+ $field_name = 'field_' . $name;
$edit = array(
'subject' => $this->randomName(),
'message' => $this->randomName(),
diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php
index acef71e..a5007b3 100644
--- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php
+++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAdminTest.php
@@ -65,12 +65,12 @@ protected function getAllOptionsList($element) {
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 . '/fields', array(
- 'fields[_add_new_field][label]' => 'Test label',
- 'fields[_add_new_field][field_name]' => 'test',
- 'fields[_add_new_field][type]' => 'entity_reference',
- ), t('Save'));
+ // First step: 'Add new field'.
+ $this->drupalPostForm($bundle_path . '/add-field', array(
+ '_add_new_field[label]' => 'Test label',
+ '_add_new_field[field_name]' => 'test',
+ 'type' => 'entity_reference',
+ ), t('Save field settings'));
// Node should be selected by default.
$this->assertFieldByName('field[settings][target_type]', 'node');
@@ -106,6 +106,7 @@ public function testFieldAdminHandler() {
), t('Save settings'));
// Check that the field appears in the overview form.
+ $this->drupalGet($bundle_path . '/fields');
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', 'Test label', 'Field was created and appears in the overview page.');
}
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
index 13c96b5..7e78628 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
@@ -68,6 +68,7 @@ public function getRegions() {
'content' => array(
'title' => $this->t('Content'),
'invisible' => TRUE,
+ 'rows_order' => array(),
// @todo Bring back this message in https://drupal.org/node/1963340.
//'message' => $this->t('No fields are present yet.'),
),
@@ -116,6 +117,19 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
),
);
+ // @todo
+ $form['inline_actions'] = array(
+ '#prefix' => '
',
+ );
+ $form['inline_actions']['add'] = array(
+ '#theme' => 'menu_local_action',
+ '#link' => array(
+ 'href' => $this->adminPath . '/add-field',
+ 'title' => t('Add field'),
+ ),
+ );
+
// Fields.
foreach ($instances as $name => $instance) {
$field = $instance->getField();
@@ -167,114 +181,6 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
}
}
- // Gather valid field types.
- $field_type_options = array();
- foreach ($field_types as $name => $field_type) {
- // Skip field types which should not be added via user interface.
- if (empty($field_type['no_ui'])) {
- $field_type_options[$name] = $field_type['label'];
- }
- }
- asort($field_type_options);
-
- // Additional row: add new field.
- if ($field_type_options) {
- $name = '_add_new_field';
- $table[$name] = array(
- '#attributes' => array('class' => array('add-new')),
- 'label' => array(
- '#type' => 'textfield',
- '#title' => $this->t('New field label'),
- '#title_display' => 'invisible',
- '#size' => 15,
- '#description' => $this->t('Label'),
- '#prefix' => '',
- ),
- 'field_name' => array(
- '#type' => 'machine_name',
- '#title' => $this->t('New field name'),
- '#title_display' => 'invisible',
- // This field should stay LTR even for RTL languages.
- '#field_prefix' => '' . $field_prefix,
- '#field_suffix' => '',
- '#size' => 15,
- '#description' => $this->t('A unique machine-readable name containing letters, numbers, and underscores.'),
- // Calculate characters depending on the length of the field prefix
- // setting. Maximum length is 32.
- '#maxlength' => Field::NAME_MAX_LENGTH - strlen($field_prefix),
- '#prefix' => '
',
- '#machine_name' => array(
- 'source' => array('fields', $name, 'label'),
- 'exists' => array($this, 'fieldNameExists'),
- 'standalone' => TRUE,
- 'label' => '',
- ),
- '#required' => FALSE,
- ),
- 'type' => array(
- '#type' => 'select',
- '#title' => $this->t('Type of new field'),
- '#title_display' => 'invisible',
- '#options' => $field_type_options,
- '#empty_option' => $this->t('- Select a field type -'),
- '#description' => $this->t('Type of data to store.'),
- '#attributes' => array('class' => array('field-type-select')),
- '#cell_attributes' => array('colspan' => 2),
- '#prefix' => '
',
- ),
- // Place the 'translatable' property as an explicit value so that
- // contrib modules can form_alter() the value for newly created fields.
- 'translatable' => array(
- '#type' => 'value',
- '#value' => FALSE,
- ),
- );
- }
-
- // Additional row: re-use existing field.
- $existing_fields = $this->getExistingFieldOptions();
- if ($existing_fields) {
- // Build list of options.
- $existing_field_options = array();
- foreach ($existing_fields as $field_name => $info) {
- $text = $this->t('@type: @field (@label)', array(
- '@type' => $info['type_label'],
- '@label' => $info['label'],
- '@field' => $info['field'],
- ));
- $existing_field_options[$field_name] = truncate_utf8($text, 80, FALSE, TRUE);
- }
- asort($existing_field_options);
- $name = '_add_existing_field';
- $table[$name] = array(
- '#attributes' => array('class' => array('add-new')),
- '#row_type' => 'add_new_field',
- '#region_callback' => array($this, 'getRowRegion'),
- 'label' => array(
- '#type' => 'textfield',
- '#title' => $this->t('Existing field label'),
- '#title_display' => 'invisible',
- '#size' => 15,
- '#description' => $this->t('Label'),
- '#attributes' => array('class' => array('label-textfield')),
- '#prefix' => '',
- ),
- 'field_name' => array(
- '#type' => 'select',
- '#title' => $this->t('Existing field to share'),
- '#title_display' => 'invisible',
- '#options' => $existing_field_options,
- '#empty_option' => $this->t('- Select an existing field -'),
- '#description' => $this->t('Field to share'),
- '#attributes' => array('class' => array('field-select')),
- '#cell_attributes' => array('colspan' => 3),
- '#prefix' => '
',
- ),
- );
- }
-
// We can set the 'rows_order' element, needed by theme_field_ui_table(),
// here instead of a #pre_render callback because this form doesn't have the
// tabledrag behavior anymore.
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php b/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php
index 6d268d8..3fad891 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/FieldUI.php
@@ -7,6 +7,7 @@
namespace Drupal\field_ui;
+use Drupal\Component\Utility\Url;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -26,7 +27,7 @@ public static function getNextDestination(Request $request) {
if (!empty($destinations)) {
$request->query->remove('destinations');
$path = array_shift($destinations);
- $options = drupal_parse_url($path);
+ $options = Url::parse($path);
if ($destinations) {
$options['query']['destinations'] = $destinations;
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldAddForm.php
similarity index 51%
copy from core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
copy to core/modules/field_ui/lib/Drupal/field_ui/Form/FieldAddForm.php
index 13c96b5..e3f5cb0 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/FieldOverview.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldAddForm.php
@@ -2,172 +2,153 @@
/**
* @file
- * Contains \Drupal\field_ui\FieldOverview.
+ * Contains \Drupal\field_ui\Form\FieldAddForm.
*/
-namespace Drupal\field_ui;
+namespace Drupal\field_ui\Form;
+use Drupal\Component\Utility\Url;
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\Field\FieldTypePluginManager;
-use Drupal\Core\Extension\ModuleHandlerInterface;
-use Drupal\field_ui\OverviewBase;
-use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Form\FormBase;
use Drupal\field\Entity\Field;
+use Drupal\field\FieldInfo;
+use Symfony\Component\DependencyInjection\ContainerInterface;
/**
- * Field UI field overview form.
+ * Provides a form for the add field page.
*/
-class FieldOverview extends OverviewBase {
+class FieldAddForm extends FormBase {
/**
- * The field type manager.
+ * The field instance being edited.
*
- * @var \Drupal\Core\Entity\Field\FieldTypePluginManager
+ * @var \Drupal\field\Entity\FieldInstance
+ */
+ protected $instance;
+
+ /**
+ * The name of the entity type.
+ *
+ * @var string
+ */
+ protected $entity_type = '';
+
+ /**
+ * The entity bundle.
+ *
+ * @var string
+ */
+ protected $bundle = '';
+
+ /**
+ * The entity view or form mode.
+ *
+ * @var string
*/
- protected $fieldTypeManager;
+ protected $mode = '';
/**
- * The module handler service.
+ * The admin path of the overview page.
*
- * @var \Drupal\Core\Extension\ModuleHandlerInterface
+ * @var string
+ */
+ protected $adminPath = NULL;
+
+ /**
+ * The entity manager.
+ *
+ * @var \Drupal\Core\Entity\EntityManager
+ */
+ protected $entityManager;
+
+ /**
+ * The field info service.
+ *
+ * @var \Drupal\field\FieldInfo
+ */
+ protected $fieldInfo;
+
+ /**
+ * The field type plugin manager.
+ *
+ * @var \Drupal\Core\Entity\Field\FieldTypePluginManager
*/
- protected $moduleHandler;
+ protected $fieldTypePluginManager;
/**
- * Constructs a new FieldOverview.
+ * Constructs a new FieldAddForm object.
*
* @param \Drupal\Core\Entity\EntityManager $entity_manager
* The entity manager.
- * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_manager
- * The field type manager
- * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
- * The module handler to invoke hooks on.
+ * @param \Drupal\field\FieldInfo $field_info
+ * The field info service.
+ * @param \Drupal\Core\Entity\Field\FieldTypePluginManager $field_type_plugin_manager
+ * The field type plugin manager.
*/
- public function __construct(EntityManager $entity_manager, FieldTypePluginManager $field_type_manager, ModuleHandlerInterface $module_handler) {
- parent::__construct($entity_manager);
- $this->fieldTypeManager = $field_type_manager;
- $this->moduleHandler = $module_handler;
+ public function __construct(EntityManager $entity_manager, FieldInfo $field_info, FieldTypePluginManager $field_type_plugin_manager) {
+ $this->entityManager = $entity_manager;
+ $this->fieldInfo = $field_info;
+ $this->fieldTypePluginManager = $field_type_plugin_manager;
}
/**
* {@inheritdoc}
*/
- public static function create(ContainerInterface $container) {
- return new static(
- $container->get('entity.manager'),
- $container->get('plugin.manager.entity.field.field_type'),
- $container->get('module_handler')
- );
+ public function getFormID() {
+ return 'field_ui_field_add_form';
}
/**
* {@inheritdoc}
*/
- public function getRegions() {
- return array(
- 'content' => array(
- 'title' => $this->t('Content'),
- 'invisible' => TRUE,
- // @todo Bring back this message in https://drupal.org/node/1963340.
- //'message' => $this->t('No fields are present yet.'),
- ),
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('entity.manager'),
+ $container->get('field.info'),
+ $container->get('plugin.manager.entity.field.field_type')
);
}
/**
* {@inheritdoc}
*/
- public function getFormID() {
- return 'field_ui_field_overview_form';
- }
+ public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL, $form_mode = NULL) {
+ $entity_info = $this->entityManager->getDefinition($entity_type);
+ if (!empty($entity_info['bundle_prefix'])) {
+ $bundle = $entity_info['bundle_prefix'] . $bundle;
+ }
- /**
- * {@inheritdoc}
- */
- public function buildForm(array $form, array &$form_state, $entity_type = NULL, $bundle = NULL) {
- parent::buildForm($form, $form_state, $entity_type, $bundle);
+ $this->entity_type = $entity_type;
+ $this->bundle = $bundle;
+ $this->mode = $form_mode;
+ $this->adminPath = $this->entityManager->getAdminPath($this->entity_type, $this->bundle);
// Gather bundle information.
- $instances = field_info_instances($this->entity_type, $this->bundle);
- $field_types = $this->fieldTypeManager->getDefinitions();
+ $instances = $this->fieldInfo->getBundleInstances($entity_type, $bundle);
+ $field_types = $this->fieldTypePluginManager->getDefinitions();
+ $extra_fields = $this->fieldInfo->getBundleExtraFields($entity_type, $bundle);
+ $extra_fields = isset($extra_fields['form']) ? $extra_fields['form'] : array();
// Field prefix.
- $field_prefix = \Drupal::config('field_ui.settings')->get('field_prefix');
+ $field_prefix = $this->config('field_ui.settings')->get('field_prefix');
- $form += array(
+ $form = array(
'#entity_type' => $this->entity_type,
'#bundle' => $this->bundle,
'#fields' => array_keys($instances),
- );
-
- $table = array(
- '#type' => 'field_ui_table',
+ '#extra' => array_keys($extra_fields),
'#tree' => TRUE,
- '#header' => array(
- $this->t('Label'),
- $this->t('Machine name'),
- $this->t('Field type'),
- $this->t('Operations'),
- ),
- '#regions' => $this->getRegions(),
'#attributes' => array(
'class' => array('field-ui-overview'),
- 'id' => 'field-overview',
+ 'id' => 'field-display-overview',
),
+ // @todo Remove once _title from \Drupal\field_ui\Routing\RouteSubscriber
+ // will start to work.
+ '#title' => 'Add a new field',
);
- // Fields.
- foreach ($instances as $name => $instance) {
- $field = $instance->getField();
- $admin_field_path = $this->adminPath . '/fields/' . $instance->id();
- $table[$name] = array(
- '#attributes' => array(
- 'id' => drupal_html_class($name),
- ),
- 'label' => array(
- '#markup' => check_plain($instance->getFieldLabel()),
- ),
- 'field_name' => array(
- '#markup' => $instance->getFieldName(),
- ),
- 'type' => array(
- '#type' => 'link',
- '#title' => $field_types[$field->getFieldType()]['label'],
- '#href' => $admin_field_path . '/field',
- '#options' => array('attributes' => array('title' => $this->t('Edit field settings.'))),
- ),
- );
-
- $links = array();
- $links['edit'] = array(
- 'title' => $this->t('Edit'),
- 'href' => $admin_field_path,
- 'attributes' => array('title' => $this->t('Edit instance settings.')),
- );
- $links['field-settings'] = array(
- 'title' => $this->t('Field settings'),
- 'href' => $admin_field_path . '/field',
- 'attributes' => array('title' => $this->t('Edit field settings.')),
- );
- $links['delete'] = array(
- 'title' => $this->t('Delete'),
- 'href' => "$admin_field_path/delete",
- 'attributes' => array('title' => $this->t('Delete instance.')),
- );
- // Allow altering the operations on this entity listing.
- $this->moduleHandler->alter('entity_operation', $links, $instance);
- $table[$name]['operations']['data'] = array(
- '#type' => 'operations',
- '#links' => $links,
- );
-
- if (!empty($field->locked)) {
- $table[$name]['operations'] = array('#markup' => $this->t('Locked'));
- $table[$name]['#attributes']['class'][] = 'menu-disabled';
- }
- }
-
- // Gather valid field types.
+ // Gather valid field types to add.
$field_type_options = array();
foreach ($field_types as $name => $field_type) {
// Skip field types which should not be added via user interface.
@@ -177,24 +158,64 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
}
asort($field_type_options);
- // Additional row: add new field.
+ $form['type'] = array(
+ '#type' => 'select',
+ '#title' => $this->t('Type of new field'),
+ '#title_display' => 'invisible',
+ '#options' => $field_type_options,
+ '#empty_option' => $this->t('- Select a field type -'),
+ '#description' => $this->t('Type of data to store.'),
+ '#attributes' => array('class' => array('field-type-select')),
+ );
+
+ // Determine which options from the 'type' field already have existing
+ // fields and add them to the $states array so we can determine if the
+ // new-or-existing select list should be displayed.
+ $existing_fields = $this->getExistingFieldOptions();
+
+ $states[] = array('value' => FALSE);
+ foreach ($existing_fields as $field) {
+ $states[] = array('value' => $field['type']);
+ }
+
+ $form['new-or-existing'] = array(
+ '#type' => 'select',
+ '#title' => $this->t('New or Existing'),
+ '#options' => array(
+ $this->t('New'),
+ $this->t('Existing'),
+ ),
+ '#empty_option' => $this->t('- New or Existing -'),
+ '#states' => array(
+ 'visible' => array(
+ 'select[name="type"]' => $states,
+ ),
+ ),
+ );
+
if ($field_type_options) {
+ $states[] = array('value' => '');
$name = '_add_new_field';
- $table[$name] = array(
- '#attributes' => array('class' => array('add-new')),
+ $form[$name] = array(
+ '#type' => 'container',
+ '#attributes' => array('class' => array('new-field-settings')),
+ // Only show this field if a type has been selected and 'Existing'
+ // has not explicitly been selected.
+ '#states' => array(
+ 'invisible' => array(
+ 'select[name="type"]' => $states,
+ 'select[name="new-or-existing"]' => array('!value' => 0),
+ ),
+ ),
'label' => array(
'#type' => 'textfield',
'#title' => $this->t('New field label'),
- '#title_display' => 'invisible',
'#size' => 15,
'#description' => $this->t('Label'),
- '#prefix' => '',
),
'field_name' => array(
'#type' => 'machine_name',
'#title' => $this->t('New field name'),
- '#title_display' => 'invisible',
// This field should stay LTR even for RTL languages.
'#field_prefix' => '' . $field_prefix,
'#field_suffix' => '',
@@ -203,26 +224,14 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
// Calculate characters depending on the length of the field prefix
// setting. Maximum length is 32.
'#maxlength' => Field::NAME_MAX_LENGTH - strlen($field_prefix),
- '#prefix' => '
',
'#machine_name' => array(
- 'source' => array('fields', $name, 'label'),
+ 'source' => array($name, 'label'),
'exists' => array($this, 'fieldNameExists'),
'standalone' => TRUE,
'label' => '',
),
'#required' => FALSE,
),
- 'type' => array(
- '#type' => 'select',
- '#title' => $this->t('Type of new field'),
- '#title_display' => 'invisible',
- '#options' => $field_type_options,
- '#empty_option' => $this->t('- Select a field type -'),
- '#description' => $this->t('Type of data to store.'),
- '#attributes' => array('class' => array('field-type-select')),
- '#cell_attributes' => array('colspan' => 2),
- '#prefix' => '
',
- ),
// Place the 'translatable' property as an explicit value so that
// contrib modules can form_alter() the value for newly created fields.
'translatable' => array(
@@ -233,7 +242,6 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
}
// Additional row: re-use existing field.
- $existing_fields = $this->getExistingFieldOptions();
if ($existing_fields) {
// Build list of options.
$existing_field_options = array();
@@ -246,46 +254,42 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
$existing_field_options[$field_name] = truncate_utf8($text, 80, FALSE, TRUE);
}
asort($existing_field_options);
+
$name = '_add_existing_field';
- $table[$name] = array(
- '#attributes' => array('class' => array('add-new')),
- '#row_type' => 'add_new_field',
- '#region_callback' => array($this, 'getRowRegion'),
- 'label' => array(
- '#type' => 'textfield',
- '#title' => $this->t('Existing field label'),
- '#title_display' => 'invisible',
- '#size' => 15,
- '#description' => $this->t('Label'),
- '#attributes' => array('class' => array('label-textfield')),
- '#prefix' => '',
+ $form[$name] = array(
+ '#type' => 'container',
+ '#attributes' => array('class' => array('existing-field-settings')),
+ // Only show this field if 'Existing' has explicitly been selected.
+ '#states' => array(
+ 'invisible' => array(
+ 'select[name="new-or-existing"]' => array('!value' => 1),
+ ),
),
'field_name' => array(
'#type' => 'select',
'#title' => $this->t('Existing field to share'),
- '#title_display' => 'invisible',
'#options' => $existing_field_options,
'#empty_option' => $this->t('- Select an existing field -'),
'#description' => $this->t('Field to share'),
'#attributes' => array('class' => array('field-select')),
- '#cell_attributes' => array('colspan' => 3),
- '#prefix' => '
',
+ ),
+ 'label' => array(
+ '#type' => 'textfield',
+ '#title' => $this->t('Existing field label'),
+ '#size' => 15,
+ '#description' => $this->t('Label'),
+ '#attributes' => array('class' => array('label-textfield')),
),
);
}
- // We can set the 'rows_order' element, needed by theme_field_ui_table(),
- // here instead of a #pre_render callback because this form doesn't have the
- // tabledrag behavior anymore.
- foreach (element_children($table) as $name) {
- $table['#regions']['content']['rows_order'][] = $name;
- }
-
- $form['fields'] = $table;
+ // This key is used to store the current updated field.
+ $form_state += array(
+ 'formatter_settings_edit' => NULL,
+ );
$form['actions'] = array('#type' => 'actions');
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save'));
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Save field settings'));
return $form;
}
@@ -294,8 +298,14 @@ public function buildForm(array $form, array &$form_state, $entity_type = NULL,
* {@inheritdoc}
*/
public function validateForm(array &$form, array &$form_state) {
- $this->validateAddNew($form, $form_state);
- $this->validateAddExisting($form, $form_state);
+ switch($form_state['values']['new-or-existing']) {
+ case 0:
+ $this->validateAddNew($form, $form_state);
+ break;
+ case 1:
+ $this->validateAddExisting($form, $form_state);
+ break;
+ }
}
/**
@@ -306,34 +316,42 @@ public function validateForm(array &$form, array &$form_state) {
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
*
- * @see \Drupal\field_ui\FieldOverview::validateForm()
+ * @see \Drupal\field_ui\Form\FieldAddForm::validateForm()
*/
protected function validateAddNew(array $form, array &$form_state) {
- $field = $form_state['values']['fields']['_add_new_field'];
+ $field = $form_state['values']['_add_new_field'];
+ $values = $form_state['values'];
// Validate if any information was provided in the 'add new field' row.
- if (array_filter(array($field['label'], $field['field_name'], $field['type']))) {
+ if (array_filter(array($field['label'], $field['field_name'], $values['type']))) {
// Missing label.
if (!$field['label']) {
- form_set_error('fields][_add_new_field][label', $this->t('Add new field: you need to provide a label.'));
+ form_set_error('_add_new_field][label', $this->t('Add new field: you need to provide a label.'));
}
// Missing field name.
if (!$field['field_name']) {
- form_set_error('fields][_add_new_field][field_name', $this->t('Add new field: you need to provide a field name.'));
+ form_set_error('_add_new_field][field_name', $this->t('Add new field: you need to provide a field name.'));
}
// Field name validation.
else {
$field_name = $field['field_name'];
// Add the field prefix.
- $field_name = \Drupal::config('field_ui.settings')->get('field_prefix') . $field_name;
- form_set_value($form['fields']['_add_new_field']['field_name'], $field_name, $form_state);
+ $field_prefix = $this->config('field_ui.settings')->get('field_prefix');
+
+ // Check if the field name is not longer then the max_length.
+ if(Field::NAME_MAX_LENGTH - (strlen($field_prefix) + strlen($field_name)) < 0) {
+ form_set_error('_add_new_field][field_name', $this->t('New field name cannot be longer than %max_length characters but is currently %current_length characters long.', array('%max_length' => Field::NAME_MAX_LENGTH - strlen($field_prefix), 'current_length' => strlen($field_name))));
+ }
+
+ $field_name = $field_prefix . $field_name;
+ form_set_value($form['_add_new_field']['field_name'], $field_name, $form_state);
}
// Missing field type.
- if (!$field['type']) {
- form_set_error('fields][_add_new_field][type', $this->t('Add new field: you need to select a field type.'));
+ if (!$values['type']) {
+ form_set_error('_add_new_field][type', $this->t('Add new field: you need to select a field type.'));
}
}
}
@@ -346,49 +364,48 @@ protected function validateAddNew(array $form, array &$form_state) {
* @param array $form_state
* A reference to a keyed array containing the current state of the form.
*
- * @see \Drupal\field_ui\FieldOverview::validate()
+ * @see \Drupal\field_ui\Form\FieldAddForm::validateForm()
*/
protected function validateAddExisting(array $form, array &$form_state) {
// The form element might be absent if no existing fields can be added to
// this bundle.
- if (isset($form_state['values']['fields']['_add_existing_field'])) {
- $field = $form_state['values']['fields']['_add_existing_field'];
+ if (isset($form_state['values']['_add_existing_field'])) {
+ $field = $form_state['values']['_add_existing_field'];
// Validate if any information was provided in the
// 're-use existing field' row.
if (array_filter(array($field['label'], $field['field_name']))) {
// Missing label.
if (!$field['label']) {
- form_set_error('fields][_add_existing_field][label', $this->t('Re-use existing field: you need to provide a label.'));
+ form_set_error('_add_existing_field][label', $this->t('Re-use existing field: you need to provide a label.'));
}
// Missing existing field name.
if (!$field['field_name']) {
- form_set_error('fields][_add_existing_field][field_name', $this->t('Re-use existing field: you need to select a field.'));
+ form_set_error('_add_existing_field][field_name', $this->t('Re-use existing field: you need to select a field.'));
}
}
}
}
/**
- * Overrides \Drupal\field_ui\OverviewBase::submitForm().
+ * {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
- $form_values = $form_state['values']['fields'];
$destinations = array();
// Create new field.
- if (!empty($form_values['_add_new_field']['field_name'])) {
- $values = $form_values['_add_new_field'];
+ if (!empty($form_state['values']['_add_new_field']['field_name'])) {
+ $values = $form_state['values']['_add_new_field'];
$field = array(
- 'name' => $values['field_name'],
'entity_type' => $this->entity_type,
- 'type' => $values['type'],
- 'translatable' => $values['translatable'],
+ 'name' => $form_state['values']['_add_new_field']['field_name'],
+ 'type' => $form_state['values']['type'],
+ 'translatable' => $form_state['values']['_add_new_field']['translatable'],
);
$instance = array(
- 'field_name' => $values['field_name'],
+ 'field_name' => $field['name'],
'entity_type' => $this->entity_type,
'bundle' => $this->bundle,
'label' => $values['label'],
@@ -404,14 +421,14 @@ public function submitForm(array &$form, array &$form_state) {
// default widget and settings). It stays hidden for other form modes
// until it is explicitly configured.
entity_get_form_display($this->entity_type, $this->bundle, 'default')
- ->setComponent($values['field_name'])
+ ->setComponent($field['name'])
->save();
// Make sure the field is displayed in the 'default' view mode (using
// default formatter and settings). It stays hidden for other view
// modes until it is explicitly configured.
entity_get_display($this->entity_type, $this->bundle, 'default')
- ->setComponent($values['field_name'])
+ ->setComponent($field['name'])
->save();
// Always show the field settings step, as the cardinality needs to be
@@ -420,24 +437,23 @@ public function submitForm(array &$form, array &$form_state) {
$destinations[] = $this->adminPath . '/fields/' . $new_instance->id();
// Store new field information for any additional submit handlers.
- $form_state['fields_added']['_add_new_field'] = $values['field_name'];
+ $form_state['fields_added']['_add_new_field'] = $field['name'];
}
catch (\Exception $e) {
- drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $instance->getFieldLabel(), '!message' => $e->getMessage())), 'error');
+ drupal_set_message($this->t('There was a problem creating field %label: !message', array('%label' => $instance['label'], '!message' => $e->getMessage())), 'error');
}
}
// Re-use existing field.
- if (!empty($form_values['_add_existing_field']['field_name'])) {
- $values = $form_values['_add_existing_field'];
- $field_name = $values['field_name'];
- $field = field_info_field($this->entity_type, $field_name);
+ if (!empty($form_state['values']['_add_existing_field']['field_name'])) {
+ $values = $form_state['values']['_add_existing_field'];
+ $field = $this->fieldInfo->getField($this->entity_type, $values['field_name']);
if (!empty($field->locked)) {
drupal_set_message($this->t('The field %label cannot be added because it is locked.', array('%label' => $values['label'])), 'error');
}
else {
$instance = array(
- 'field_name' => $field_name,
+ 'field_name' => $field->getFieldName(),
'entity_type' => $this->entity_type,
'bundle' => $this->bundle,
'label' => $values['label'],
@@ -451,14 +467,14 @@ public function submitForm(array &$form, array &$form_state) {
// default widget and settings). It stays hidden for other form modes
// until it is explicitly configured.
entity_get_form_display($this->entity_type, $this->bundle, 'default')
- ->setComponent($field_name)
+ ->setComponent($field->getFieldName())
->save();
// Make sure the field is displayed in the 'default' view mode (using
// default formatter and settings). It stays hidden for other view
// modes until it is explicitly configured.
entity_get_display($this->entity_type, $this->bundle, 'default')
- ->setComponent($field_name)
+ ->setComponent($field->getFieldName())
->save();
$destinations[] = $this->adminPath . '/fields/' . $new_instance->id();
@@ -466,7 +482,7 @@ public function submitForm(array &$form, array &$form_state) {
$form_state['fields_added']['_add_existing_field'] = $instance['field_name'];
}
catch (\Exception $e) {
- drupal_set_message($this->t('There was a problem creating field instance %label: @message.', array('%label' => $instance->getFieldLabel(), '@message' => $e->getMessage())), 'error');
+ drupal_set_message($this->t('There was a problem creating field instance %label: @message.', array('%label' => $instance['label'], '@message' => $e->getMessage())), 'error');
}
}
}
@@ -474,9 +490,9 @@ public function submitForm(array &$form, array &$form_state) {
if ($destinations) {
$destination = drupal_get_destination();
$destinations[] = $destination['destination'];
- $this->getRequest()->query->remove('destination');
+ unset($_GET['destination']);
$path = array_shift($destinations);
- $options = drupal_parse_url($path);
+ $options = Url::parse($path);
$options['query']['destinations'] = $destinations;
$form_state['redirect'] = array($options['path'], $options);
}
@@ -492,43 +508,33 @@ public function submitForm(array &$form, array &$form_state) {
* An array of existing fields keyed by field name.
*/
protected function getExistingFieldOptions() {
- $options = array();
-
- // Collect candidate field instances: all instances of fields for this
- // entity type that are not already present in the current bundle.
- $field_map = field_info_field_map();
- $instance_ids = array();
- if (!empty($field_map[$this->entity_type])) {
- foreach ($field_map[$this->entity_type] as $field_name => $data) {
- if (!in_array($this->bundle, $data['bundles'])) {
- $bundle = reset($data['bundles']);
- $instance_ids[] = $this->entity_type . '.' . $bundle . '.' . $field_name;
+ $info = array();
+ $field_types = $this->fieldTypePluginManager->getDefinitions();
+
+ $instances = $this->fieldInfo->getInstances($this->entity_type);
+ foreach ($instances as $instance) {
+ foreach ($instance as $field_name => $instance_settings) {
+ if (!($instance_settings->bundle == $this->bundle && $instance_settings->entity_type == $this->entity_type)) {
+ $field = $this->fieldInfo->getField($instance_settings->entity_type, $field_name);
+ // Don't show
+ // - locked fields,
+ // - fields already in the current bundle,
+ // - fields that cannot be added to the entity type,
+ // - fields that should not be added via user interface.
+ if (empty($field->locked)
+ && !$this->fieldInfo->getInstance($this->entity_type, $this->bundle, $field->id())
+ && empty($field_types[$field->getFieldType()]['no_ui'])) {
+ $info[$instance_settings->getFieldName()] = array(
+ 'type' => $field->getFieldType(),
+ 'type_label' => $field_types[$field->getFieldType()]['label'],
+ 'field' => $field->id(),
+ 'label' => $instance_settings->label(),
+ );
+ }
}
}
}
-
- // Load the instances and build the list of options.
- if ($instance_ids) {
- $field_types = $this->fieldTypeManager->getDefinitions();
- $instances = $this->entityManager->getStorageController('field_instance')->loadMultiple($instance_ids);
- foreach ($instances as $instance) {
- // Do not show:
- // - locked fields,
- // - fields that should not be added via user interface.
- $field_type = $instance->getFieldType();
- $field = $instance->getField();
- if (empty($field->locked) && empty($field_types[$field_type]['no_ui'])) {
- $options[$instance->getFieldName()] = array(
- 'type' => $field_type,
- 'type_label' => $field_types[$field_type]['label'],
- 'field' => $instance->getFieldName(),
- 'label' => $instance->getFieldLabel(),
- );
- }
- }
- }
-
- return $options;
+ return $info;
}
/**
@@ -541,12 +547,18 @@ protected function getExistingFieldOptions() {
* Whether or not the field machine name is taken.
*/
public function fieldNameExists($value) {
- // Prefix with 'field_'.
- $field_name = 'field_' . $value;
+ // Get the configured field prefix.
+ $field_prefix = $this->config('field_ui.settings')->get('field_prefix');
// We need to check inactive fields as well, so we can't use
// field_info_fields().
- return (bool) field_read_fields(array('entity_type' => $this->entity_type, 'name' => $field_name), array('include_inactive' => TRUE));
+ return (bool) $this->entityManager
+ ->getStorageController('field_entity')
+ ->loadByProperties(array(
+ 'field_name' => $field_prefix . $value,
+ 'include_inactive' => TRUE,
+ 'include_deleted' => TRUE)
+ );
}
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
index 2fbe6f7..727341a 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Form/FieldInstanceEditForm.php
@@ -188,7 +188,7 @@ public function submitForm(array &$form, array &$form_state) {
drupal_set_message($this->t('Saved %label configuration.', array('%label' => $this->instance->getFieldLabel())));
- $form_state['redirect'] = $this->getNextDestination();
+ $form_state['redirect'] = $this->entityManager->getAdminPath($this->instance->entity_type, $this->instance->bundle) . '/fields';
}
/**
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php
index 456e1fd..6292ddb 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Routing/RouteSubscriber.php
@@ -120,6 +120,16 @@ public function routes(RouteBuildEvent $event) {
);
$collection->add("field_ui.display_overview_$entity_type", $route);
+ $route = new Route(
+ "$path/add-field",
+ array(
+ '_form' => '\Drupal\field_ui\Form\FieldAddForm',
+ '_title' => 'Add a new field',
+ ) + $defaults,
+ array('_permission' => 'administer ' . $entity_type . ' fields')
+ );
+ $collection->add("field_ui.add.$entity_type", $route);
+
foreach (entity_get_view_modes($entity_type) as $view_mode => $view_mode_info) {
$route = new Route(
"$path/display/$view_mode",
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php
index 9116d09..0640935 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php
@@ -66,12 +66,13 @@ function setUp() {
function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(), $instance_edit = array()) {
// Use 'test_field' field type by default.
$initial_edit += array(
- 'fields[_add_new_field][type]' => 'test_field',
+ 'type' => 'test_field',
+ 'new-or-existing' => 0,
);
- $label = $initial_edit['fields[_add_new_field][label]'];
+ $label = $initial_edit['_add_new_field[label]'];
// First step : 'Add new field' on the 'Manage fields' page.
- $this->drupalPostForm("$bundle_path/fields", $initial_edit, t('Save'));
+ $this->drupalPostForm("$bundle_path/add-field", $initial_edit, t('Save field settings'));
$this->assertRaw(t('These settings apply to the %label field everywhere it is used.', array('%label' => $label)), 'Field settings page was displayed.');
// Second step : 'Field settings' form.
@@ -83,6 +84,7 @@ function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(),
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.');
// Check that the field appears in the overview form.
+ $this->drupalGet("$bundle_path/fields");
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, 'Field was created and appears in the overview page.');
}
@@ -99,16 +101,20 @@ function fieldUIAddNewField($bundle_path, $initial_edit, $field_edit = array(),
* form).
*/
function fieldUIAddExistingField($bundle_path, $initial_edit, $instance_edit = array()) {
- $label = $initial_edit['fields[_add_existing_field][label]'];
+ $initial_edit += array(
+ 'new-or-existing' => 1,
+ );
+ $label = $initial_edit['_add_existing_field[label]'];
// First step : 'Re-use existing field' on the 'Manage fields' page.
- $this->drupalPostForm("$bundle_path/fields", $initial_edit, t('Save'));
+ $this->drupalPostForm("$bundle_path/add-field", $initial_edit, t('Save field settings'));
// Second step : 'Instance settings' form.
$this->drupalPostForm(NULL, $instance_edit, t('Save settings'));
$this->assertRaw(t('Saved %label configuration.', array('%label' => $label)), 'Redirected to "Manage fields" page.');
// Check that the field appears in the overview form.
+ $this->drupalGet("$bundle_path/fields");
$this->assertFieldByXPath('//table[@id="field-overview"]//td[1]', $label, 'Field was created and appears in the overview page.');
}
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
index 0cb1c93..5712caf 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageDisplayTest.php
@@ -38,8 +38,8 @@ function testFormatterUI() {
// Create a field, and a node with some data for the field.
$edit = array(
- 'fields[_add_new_field][label]' => 'Test field',
- 'fields[_add_new_field][field_name]' => 'test',
+ '_add_new_field[label]' => 'Test field',
+ '_add_new_field[field_name]' => 'test',
);
$this->fieldUIAddNewField($manage_fields, $edit);
@@ -104,8 +104,8 @@ public function testWidgetUI() {
// Create a field, and a node with some data for the field.
$edit = array(
- 'fields[_add_new_field][label]' => 'Test field',
- 'fields[_add_new_field][field_name]' => 'test',
+ '_add_new_field[label]' => 'Test field',
+ '_add_new_field[field_name]' => 'test',
);
$this->fieldUIAddNewField($manage_fields, $edit);
@@ -166,8 +166,8 @@ public function testWidgetUI() {
function testViewModeCustom() {
// Create a field, and a node with some data for the field.
$edit = array(
- 'fields[_add_new_field][label]' => 'Test field',
- 'fields[_add_new_field][field_name]' => 'test',
+ '_add_new_field[label]' => 'Test field',
+ '_add_new_field[field_name]' => 'test',
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit);
// For this test, use a formatter setting value that is an integer unlikely
@@ -238,8 +238,8 @@ function testViewModeCustom() {
function testNonInitializedFields() {
// Create a test field.
$edit = array(
- 'fields[_add_new_field][label]' => 'Test',
- 'fields[_add_new_field][field_name]' => 'test',
+ '_add_new_field[label]' => 'Test',
+ '_add_new_field[field_name]' => 'test',
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit);
diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
index 1a8f65e..efebc47 100644
--- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
+++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php
@@ -8,6 +8,7 @@
namespace Drupal\field_ui\Tests;
use Drupal\Core\Language\Language;
+use Drupal\field\Entity\Field;
/**
* Tests the functionality of the 'Manage fields' screen.
@@ -97,11 +98,8 @@ function manageFieldsPage($type = '') {
$this->assertRaw($table_header . '', format_string('%table_header table header was found.', array('%table_header' => $table_header)));
}
- // "Add new field" and "Re-use existing field" aren't a table heading so just
- // test the text.
- foreach (array('Add new field', 'Re-use existing field') as $element) {
- $this->assertText($element, format_string('"@element" was found.', array('@element' => $element)));
- }
+ // "Add field" is a button.
+ $this->assertText('Add field', 'Add field button was found.');
}
/**
@@ -113,8 +111,8 @@ function manageFieldsPage($type = '') {
function createField() {
// Create a test field.
$edit = array(
- 'fields[_add_new_field][label]' => $this->field_label,
- 'fields[_add_new_field][field_name]' => $this->field_name_input,
+ '_add_new_field[label]' => $this->field_label,
+ '_add_new_field[field_name]' => $this->field_name_input,
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit);
}
@@ -152,9 +150,9 @@ function updateField() {
* Tests adding an existing field in another content type.
*/
function addExistingField() {
- // Check "Re-use existing field" appears.
- $this->drupalGet('admin/structure/types/manage/page/fields');
- $this->assertRaw(t('Re-use existing field'), '"Re-use existing field" was found.');
+ // Check "Existing field to share" appears.
+ $this->drupalGet('admin/structure/types/manage/page/add-field');
+ $this->assertRaw('Existing field to share', '"Existing field to share" 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.
@@ -162,8 +160,8 @@ function addExistingField() {
// Add a new field based on an existing field.
$edit = array(
- 'fields[_add_existing_field][label]' => $this->field_label . '_2',
- 'fields[_add_existing_field][field_name]' => $this->field_name,
+ '_add_existing_field[label]' => $this->field_label . '_2',
+ '_add_existing_field[field_name]' => $this->field_name,
);
$this->fieldUIAddExistingField("admin/structure/types/manage/page", $edit);
}
@@ -246,16 +244,16 @@ function testFieldPrefix() {
// Try to create the field.
$edit = array(
- 'fields[_add_new_field][label]' => $field_exceed_max_length_label,
- 'fields[_add_new_field][field_name]' => $field_exceed_max_length_input,
+ '_add_new_field[label]' => $field_exceed_max_length_label,
+ '_add_new_field[field_name]' => $field_exceed_max_length_input,
);
- $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/fields', $edit, t('Save'));
- $this->assertText('New field name cannot be longer than 22 characters but is currently 23 characters long.');
+ $this->drupalPostForm('admin/structure/types/manage/' . $this->type . '/add-field', $edit, t('Save field settings'));
+ $this->assertText(format_string('New field name cannot be longer than @max_length characters but is currently @current_length characters long.', array('@max_length' => (Field::NAME_MAX_LENGTH - strlen($field_prefix)), '@current_length' => strlen($field_exceed_max_length_input))));
// Create a valid field.
$edit = array(
- 'fields[_add_new_field][label]' => $this->field_label,
- 'fields[_add_new_field][field_name]' => $this->field_name_input,
+ '_add_new_field[label]' => $this->field_label,
+ '_add_new_field[field_name]' => $this->field_name_input,
);
$this->fieldUIAddNewField('admin/structure/types/manage/' . $this->type, $edit);
$this->drupalGet('admin/structure/types/manage/' . $this->type . '/fields/node.' . $this->type . '.' . $field_prefix . $this->field_name_input);
@@ -329,8 +327,8 @@ function testDeleteField() {
// Create a new field.
$bundle_path1 = 'admin/structure/types/manage/' . $this->type;
$edit1 = array(
- 'fields[_add_new_field][label]' => $this->field_label,
- 'fields[_add_new_field][field_name]' => $this->field_name_input,
+ '_add_new_field[label]' => $this->field_label,
+ '_add_new_field[field_name]' => $this->field_name_input,
);
$this->fieldUIAddNewField($bundle_path1, $edit1);
@@ -342,8 +340,8 @@ function testDeleteField() {
// Add an instance to the second node type.
$bundle_path2 = 'admin/structure/types/manage/' . $type_name2;
$edit2 = array(
- 'fields[_add_existing_field][label]' => $this->field_label,
- 'fields[_add_existing_field][field_name]' => $this->field_name,
+ '_add_existing_field[label]' => $this->field_label,
+ '_add_existing_field[field_name]' => $this->field_name,
);
$this->fieldUIAddExistingField($bundle_path2, $edit2);
@@ -441,7 +439,7 @@ function testHiddenFields() {
// on other bundles.
$bundle_path = 'admin/structure/types/manage/article/fields/';
$this->drupalGet($bundle_path);
- $this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), "The 're-use existing field' select respects field types 'no_ui' property.");
+ $this->assertFalse($this->xpath('//select[@id="edit-add-existing-field-field-name"]//option[@value=:field_name]', array(':field_name' => $field_name)), 'The "Existing field to share" select respects field types "no_ui" property.');
}
/**
@@ -464,12 +462,12 @@ function testDuplicateFieldName() {
// field_tags already exists, so we're expecting an error when trying to
// create a new field with the same name.
$edit = array(
- 'fields[_add_new_field][field_name]' => 'tags',
- 'fields[_add_new_field][label]' => $this->randomName(),
- 'fields[_add_new_field][type]' => 'taxonomy_term_reference',
+ '_add_new_field[field_name]' => 'tags',
+ '_add_new_field[label]' => $this->randomName(),
+ 'type' => 'taxonomy_term_reference',
);
- $url = 'admin/structure/types/manage/' . $this->type . '/fields';
- $this->drupalPostForm($url, $edit, t('Save'));
+ $url = 'admin/structure/types/manage/' . $this->type . '/add-field';
+ $this->drupalPostForm($url, $edit, t('Save field settings'));
$this->assertText(t('The machine-readable name is already in use. It must be unique.'));
$this->assertUrl($url, array(), 'Stayed on the same page.');
@@ -482,8 +480,8 @@ function testDeleteTaxonomyField() {
// Create a new field.
$bundle_path = 'admin/structure/taxonomy/manage/tags';
$edit1 = array(
- 'fields[_add_new_field][label]' => $this->field_label,
- 'fields[_add_new_field][field_name]' => $this->field_name_input,
+ '_add_new_field[label]' => $this->field_label,
+ '_add_new_field[field_name]' => $this->field_name_input,
);
$this->fieldUIAddNewField($bundle_path, $edit1);
diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
index d328bd5..d972e83 100644
--- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
+++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php
@@ -253,11 +253,11 @@ function testPrivateFileComment() {
// Create a new field.
$this->container->get('comment.manager')->addDefaultField('node', 'article');
$edit = array(
- 'fields[_add_new_field][label]' => $label = $this->randomName(),
- 'fields[_add_new_field][field_name]' => $name = strtolower($this->randomName()),
- 'fields[_add_new_field][type]' => 'file',
+ '_add_new_field[label]' => $label = $this->randomString(),
+ '_add_new_field[field_name]' => $name = strtolower($this->randomName()),
+ 'type' => 'file',
);
- $this->drupalPostForm('admin/structure/comments/manage/node__comment/fields', $edit, t('Save'));
+ $this->drupalPostForm('admin/structure/comments/manage/node__comment/add-field', $edit, t('Save field settings'));
$edit = array('field[settings][uri_scheme]' => 'private');
$this->drupalPostForm(NULL, $edit, t('Save field settings'));
$this->drupalPostForm(NULL, array(), t('Save settings'));
diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldUITest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldUITest.php
index 97fda35..b18ccb0 100644
--- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldUITest.php
+++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldUITest.php
@@ -48,11 +48,11 @@ function testFieldUI() {
$label = $this->randomName();
$field_name = drupal_strtolower($label);
$edit = array(
- 'fields[_add_new_field][label]' => $label,
- 'fields[_add_new_field][field_name]' => $field_name,
- 'fields[_add_new_field][type]' => 'link',
+ '_add_new_field[label]' => $label,
+ '_add_new_field[field_name]' => $field_name,
+ 'type' => 'link',
);
- $this->drupalPostForm("$type_path/fields", $edit, t('Save'));
+ $this->drupalPostForm($type_path . '/add-field', $edit, t('Save field settings'));
// Proceed to the Edit (field instance settings) page.
$this->drupalPostForm(NULL, array(), t('Save field settings'));
// Proceed to the Manage fields overview page.
diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
index 8a1d9b2..bd8a421 100644
--- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
+++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php
@@ -163,11 +163,11 @@ function testNumberIntegerField() {
$label = $this->randomName();
$field_name = drupal_strtolower($label);
$edit = array(
- 'fields[_add_new_field][label]'=> $label,
- 'fields[_add_new_field][field_name]' => $field_name,
- 'fields[_add_new_field][type]' => 'number_integer',
+ '_add_new_field[label]'=> $label,
+ '_add_new_field[field_name]' => $field_name,
+ 'type' => 'number_integer',
);
- $this->drupalPostForm(NULL, $edit, t('Save'));
+ $this->drupalPostForm('admin/structure/types/manage/' . $type . '/add-field', $edit, t('Save field settings'));
// Add prefix and suffix for the newly-created field.
$prefix = $this->randomName();