diff --git a/core/includes/form.inc b/core/includes/form.inc index 5c0c5cf..9868e60 100644 --- a/core/includes/form.inc +++ b/core/includes/form.inc @@ -991,6 +991,12 @@ function theme_fieldset($variables) { */ function theme_details($variables) { $element = $variables['element']; + + if (empty($element['#children'])) { + // Skip displaying the details element if there are no children. + return ''; + } + element_set_attributes($element, array('id')); _form_set_attributes($element, array('form-wrapper')); @@ -1963,9 +1969,6 @@ function form_process_group(&$element, &$form_state) { $form_state['groups'][$group][] = &$element; } - // Contains form element summary functionalities. - $element['#attached']['library'][] = array('system', 'drupal.form'); - return $element; } @@ -2032,6 +2035,9 @@ function form_pre_render_group($element) { } if (isset($element['#group'])) { + // Contains form element summary functionalities. + $element['#attached']['library'][] = array('system', 'drupal.form'); + $group = $element['#group']; // If this element belongs to a group, but the group-holding element does // not exist, we need to render it (at its original location). diff --git a/core/modules/datetime/datetime.module b/core/modules/datetime/datetime.module index ccf1a0c..27b52e4 100644 --- a/core/modules/datetime/datetime.module +++ b/core/modules/datetime/datetime.module @@ -46,7 +46,8 @@ function datetime_element_info() { $types['datetime'] = array( '#input' => TRUE, '#element_validate' => array('datetime_datetime_validate'), - '#process' => array('datetime_datetime_form_process'), + '#process' => array('datetime_datetime_form_process', 'form_process_group'), + '#pre_render' => array('form_pre_render_group'), '#theme' => 'datetime_form', '#theme_wrappers' => array('datetime_wrapper'), '#date_date_format' => $date_format, @@ -991,11 +992,11 @@ function datetime_form_node_form_alter(&$form, &$form_state, $form_id) { $format_type = datetime_default_format_type(); // Alter the 'Authored on' date to use datetime. - $form['author']['date']['#type'] = 'datetime'; + $form['created']['#type'] = 'datetime'; $date_format = entity_load('date_format', 'html_date')->getPattern($format_type); $time_format = entity_load('date_format', 'html_time')->getPattern($format_type); - $form['author']['date']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); - unset($form['author']['date']['#maxlength']); + $form['created']['#description'] = t('Format: %format. Leave blank to use the time of form submission.', array('%format' => datetime_format_example($date_format . ' ' . $time_format))); + unset($form['created']['#maxlength']); } /** diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php index ab8feb9..3799288 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php @@ -174,8 +174,8 @@ protected function createForumTopics($count = 5) { 'body[0][value]' => $body, // Forum posts are ordered by timestamp, so force a unique timestamp by // adding the index. - 'date[date]' => $date->format('Y-m-d'), - 'date[time]' => $date->format('H:i:s'), + 'created[date]' => $date->format('Y-m-d'), + 'created[time]' => $date->format('H:i:s'), ); // Create the forum topic, preselecting the forum ID via a URL parameter. diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index d6fda36..8dd4f82 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -34,11 +34,6 @@ protected function prepareEntity() { // Set up default values, if required. $type = entity_load('node_type', $node->bundle()); $this->settings = $type->getModuleSettings('node'); - $this->settings += array( - 'options' => array('status', 'promote'), - 'preview' => DRUPAL_OPTIONAL, - 'submitted' => TRUE, - ); // If this is a new node, fill in the default values. if ($node->isNew()) { @@ -48,8 +43,6 @@ protected function prepareEntity() { $node->$key = (int) !empty($this->settings['options'][$key]); } } - $node->setOwnerId(\Drupal::currentUser()->id()); - $node->setCreatedTime(REQUEST_TIME); } else { $node->date = format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O'); @@ -87,15 +80,6 @@ public function form(array $form, array &$form_state) { // names. $form['#attributes']['class'][0] = drupal_html_class('node-' . $node->getType() . '-form'); - // Basic node information. - // These elements are just values so they are not even sent to the client. - foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) { - $form[$key] = array( - '#type' => 'value', - '#value' => isset($node->$key) ? $node->$key : NULL, - ); - } - // Changed must be sent to the client, for later overwrite error checking. $form['changed'] = array( '#type' => 'hidden', @@ -132,17 +116,17 @@ public function form(array $form, array &$form_state) { 'js' => array(drupal_get_path('module', 'node') . '/node.js'), ), '#weight' => 20, - '#access' => $node->isNewRevision() || user_access('administer nodes'), ); - $form['revision_information']['revision']['revision'] = array( + $form['revision'] = array( '#type' => 'checkbox', '#title' => t('Create new revision'), '#default_value' => $node->isNewRevision(), - '#access' => user_access('administer nodes'), + '#access' => $node->isNewRevision() || user_access('administer nodes'), + '#group' => 'revision_information', ); - $form['revision_information']['revision']['log'] = array( + $form['log'] = array( '#type' => 'textarea', '#title' => t('Revision log message'), '#rows' => 4, @@ -153,6 +137,8 @@ public function form(array $form, array &$form_state) { ':input[name="revision"]' => array('checked' => TRUE), ), ), + '#group' => 'revision_information', + '#access' => $node->isNewRevision() || user_access('administer nodes'), ); // Node author information for administrators. @@ -177,7 +163,7 @@ public function form(array $form, array &$form_state) { '#weight' => 90, ); - $form['author']['name'] = array( + $form['uid'] = array( '#type' => 'textfield', '#title' => t('Authored by'), '#maxlength' => 60, @@ -185,19 +171,22 @@ public function form(array $form, array &$form_state) { '#default_value' => $node->getOwnerId()? $node->getOwner()->getUsername() : '', '#weight' => -1, '#description' => t('Leave blank for %anonymous.', array('%anonymous' => $user_config->get('anonymous'))), + '#group' => 'author', + '#access' => user_access('administer nodes'), ); - $form['author']['date'] = array( + $form['created'] = array( '#type' => 'textfield', '#title' => t('Authored on'), '#maxlength' => 25, '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array('%time' => !empty($node->date) ? date_format(date_create($node->date), 'Y-m-d H:i:s O') : format_date($node->getCreatedTime(), 'custom', 'Y-m-d H:i:s O'), '%timezone' => !empty($node->date) ? date_format(date_create($node->date), 'O') : format_date($node->getCreatedTime(), 'custom', 'O'))), '#default_value' => !empty($node->date) ? $node->date : '', + '#group' => 'author', + '#access' => user_access('administer nodes'), ); // Node options for administrators. $form['options'] = array( '#type' => 'details', - '#access' => user_access('administer nodes'), '#title' => t('Promotion options'), '#collapsed' => TRUE, '#group' => 'advanced', @@ -210,16 +199,20 @@ public function form(array $form, array &$form_state) { '#weight' => 95, ); - $form['options']['promote'] = array( + $form['promote'] = array( '#type' => 'checkbox', '#title' => t('Promoted to front page'), '#default_value' => $node->isPromoted(), + '#group' => 'options', + '#access' => user_access('administer nodes'), ); - $form['options']['sticky'] = array( + $form['sticky'] = array( '#type' => 'checkbox', '#title' => t('Sticky at top of lists'), '#default_value' => $node->isSticky(), + '#group' => 'options', + '#access' => user_access('administer nodes'), ); return parent::form($form, $form_state, $node); @@ -316,11 +309,11 @@ public function validate(array $form, array &$form_state) { } // Validate the "authored by" field. - if (!empty($form_state['values']['name']) && !($account = user_load_by_name($form_state['values']['name']))) { + if (!empty($form_state['values']['uid']) && !($account = user_load_by_name($form_state['values']['uid']))) { // The use of empty() is mandatory in the context of usernames // as the empty string denotes the anonymous user. In case we // are dealing with an anonymous user we set the user ID to 0. - $this->setFormError('name', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['name']))); + $this->setFormError('uid', $form_state, $this->t('The username %name does not exist.', array('%name' => $form_state['values']['uid']))); } // Validate the "authored on" field. @@ -423,15 +416,15 @@ public function buildEntity(array $form, array &$form_state) { $entity = parent::buildEntity($form, $form_state); // A user might assign the node author by entering a user name in the node // form, which we then need to translate to a user ID. - if (!empty($form_state['values']['name']) && $account = user_load_by_name($form_state['values']['name'])) { + if (!empty($form_state['values']['uid']) && $account = user_load_by_name($form_state['values']['uid'])) { $entity->setOwnerId($account->id()); } else { $entity->setOwnerId(0); } - if (!empty($form_state['values']['date']) && $form_state['values']['date'] instanceOf DrupalDateTime) { - $entity->setCreatedTime($form_state['values']['date']->getTimestamp()); + if (!empty($form_state['values']['created']) && $form_state['values']['created'] instanceOf DrupalDateTime) { + $entity->setCreatedTime($form_state['values']['created']->getTimestamp()); } else { $entity->setCreatedTime(REQUEST_TIME); diff --git a/core/modules/node/lib/Drupal/node/NodeTranslationController.php b/core/modules/node/lib/Drupal/node/NodeTranslationController.php index 9568aeb..e1c90d6 100644 --- a/core/modules/node/lib/Drupal/node/NodeTranslationController.php +++ b/core/modules/node/lib/Drupal/node/NodeTranslationController.php @@ -56,8 +56,10 @@ public function entityFormEntityBuild($entity_type, EntityInterface $entity, arr $form_controller = content_translation_form_controller($form_state); $translation = &$form_state['values']['content_translation']; $translation['status'] = $form_controller->getEntity()->isPublished(); - $translation['name'] = $form_state['values']['name']; - $translation['created'] = $form_state['values']['date']; + // $form['content_translation']['name'] is the equivalent field + // for translation author uid. + $translation['name'] = $form_state['values']['uid']; + $translation['created'] = $form_state['values']['created']; } parent::entityFormEntityBuild($entity_type, $entity, $form, $form_state); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 52dd047..c5b4514 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -149,7 +149,7 @@ public function testAuthorAutocomplete() { $this->drupalGet('node/add/page'); - $result = $this->xpath('//input[@id="edit-name" and contains(@data-autocomplete-path, "user/autocomplete")]'); + $result = $this->xpath('//input[@id="edit-uid" and contains(@data-autocomplete-path, "user/autocomplete")]'); $this->assertEqual(count($result), 0, 'No autocompletion without access user profiles.'); $admin_user = $this->drupalCreateUser(array('administer nodes', 'create page content', 'access user profiles')); @@ -157,7 +157,7 @@ public function testAuthorAutocomplete() { $this->drupalGet('node/add/page'); - $result = $this->xpath('//input[@id="edit-name" and contains(@data-autocomplete-path, "user/autocomplete")]'); + $result = $this->xpath('//input[@id="edit-uid" and contains(@data-autocomplete-path, "user/autocomplete")]'); $this->assertEqual(count($result), 1, 'Ensure that the user does have access to the autocompletion'); } diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php index 5b7389a..0aaf8df 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTranslationUITest.php @@ -155,17 +155,17 @@ protected function doTestAuthoringInfo() { 'created' => REQUEST_TIME - mt_rand(0, 1000), ); $edit = array( - 'name' => $user->getUsername(), - 'date[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), - 'date[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), + 'uid' => $user->getUsername(), + 'created[date]' => format_date($values[$langcode]['created'], 'custom', 'Y-m-d'), + 'created[time]' => format_date($values[$langcode]['created'], 'custom', 'H:i:s'), ); $this->drupalPostForm($path, $edit, $this->getFormSubmitAction($entity), array('language' => $languages[$langcode])); } $entity = entity_load($this->entityType, $this->entityId, TRUE); foreach ($this->langcodes as $langcode) { - $this->assertEqual($entity->translation[$langcode]['uid'] == $values[$langcode]['uid'], 'Translation author correctly stored.'); - $this->assertEqual($entity->translation[$langcode]['created'] == $values[$langcode]['created'], 'Translation date correctly stored.'); + $this->assertEqual($entity->translation[$langcode]['uid'], $values[$langcode]['uid'], 'Translation author correctly stored.'); + $this->assertEqual($entity->translation[$langcode]['created'], $values[$langcode]['created'], 'Translation date correctly stored.'); } } diff --git a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php index b7b0106..2361d13 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php @@ -114,21 +114,21 @@ function testPageAuthoredBy() { // Try to change the 'authored by' field to an invalid user name. $edit = array( - 'name' => 'invalid-name', + 'uid' => 'invalid-name', ); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $this->assertText('The username invalid-name does not exist.'); // Change the authored by field to an empty string, which should assign // authorship to the anonymous user (uid 0). - $edit['name'] = ''; + $edit['uid'] = ''; $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $node = node_load($node->id(), TRUE); $this->assertIdentical($node->getOwnerId(), '0', 'Node authored by anonymous user.'); // Change the authored by field to another user's name (that is not // logged in). - $edit['name'] = $this->web_user->getUsername(); + $edit['uid'] = $this->web_user->getUsername(); $this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save and keep published')); $node = node_load($node->id(), TRUE); $this->assertIdentical($node->getOwnerId(), $this->web_user->id(), 'Node authored by normal user.'); @@ -136,6 +136,6 @@ function testPageAuthoredBy() { // Check that normal users cannot change the authored by information. $this->drupalLogin($this->web_user); $this->drupalGet('node/' . $node->id() . '/edit'); - $this->assertNoFieldByName('name'); + $this->assertNoFieldByName('uid'); } } diff --git a/core/modules/system/system.module b/core/modules/system/system.module index 941ef47..7a3a4a8 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -334,8 +334,8 @@ function system_element_info() { '#size' => 60, '#maxlength' => 128, '#autocomplete_route_name' => FALSE, - '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'), - '#pre_render' => array('form_pre_render_textfield'), + '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern', 'form_process_group'), + '#pre_render' => array('form_pre_render_textfield', 'form_pre_render_group'), '#theme' => 'input__textfield', '#theme_wrappers' => array('form_element'), ); @@ -441,7 +441,8 @@ function system_element_info() { '#cols' => 60, '#rows' => 5, '#resizable' => 'vertical', - '#process' => array('ajax_process_form'), + '#process' => array('ajax_process_form', 'form_process_group'), + '#pre_render' => array('form_pre_render_group'), '#theme' => 'textarea', '#theme_wrappers' => array('form_element'), ); @@ -469,8 +470,8 @@ function system_element_info() { $types['checkbox'] = array( '#input' => TRUE, '#return_value' => 1, - '#process' => array('form_process_checkbox', 'ajax_process_form'), - '#pre_render' => array('form_pre_render_checkbox'), + '#process' => array('form_process_checkbox', 'ajax_process_form', 'form_process_group'), + '#pre_render' => array('form_pre_render_checkbox', 'form_pre_render_group'), '#theme' => 'input__checkbox', '#theme_wrappers' => array('form_element'), '#title_display' => 'after', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php index 9852d72..cddfefd 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php @@ -38,8 +38,8 @@ function testTaxonomyLegacyNode() { $date = new DrupalDateTime('1969-01-01 00:00:00'); $edit = array(); $edit['title[0][value]'] = $this->randomName(); - $edit['date[date]'] = $date->format('Y-m-d'); - $edit['date[time]'] = $date->format('H:i:s'); + $edit['created[date]'] = $date->format('Y-m-d'); + $edit['created[time]'] = $date->format('H:i:s'); $edit['body[0][value]'] = $this->randomName(); $edit['field_tags'] = $this->randomName(); $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));