Commit 6ff0d4c7 authored by webchick's avatar webchick

Issue #2177469 by Gábor Hojtsy, Aron Novak, swentel, andypost, Berdir: Move...

Issue #2177469 by Gábor Hojtsy, Aron Novak, swentel, andypost, Berdir: Move node base widgets to the top level of the form.
parent a1a5e155
......@@ -1072,7 +1072,7 @@ function theme_fieldset($variables) {
* An associative array containing:
* - element: An associative array containing the properties of the element.
* Properties used: #attributes, #children, #collapsed, #collapsible,
* #description, #id, #title, #value.
* #description, #id, #title, #value, #optional.
*
* @ingroup themeable
*/
......@@ -2041,9 +2041,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;
}
......@@ -2070,6 +2067,14 @@ function form_pre_render_details($element) {
$element['#attributes']['open'] = 'open';
}
// Do not render optional details elements if there are no children.
if (isset($element['#parents'])) {
$group = implode('][', $element['#parents']);
if (!empty($element['#optional']) && !element_get_visible_children($element['#groups'][$group])) {
$element['#printed'] = TRUE;
}
}
return $element;
}
......@@ -2110,6 +2115,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).
......
......@@ -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']);
}
/**
......
......@@ -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.
......
......@@ -35,11 +35,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()) {
......@@ -49,8 +44,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');
......@@ -88,15 +81,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',
......@@ -133,17 +117,18 @@ 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'),
'#optional' => TRUE,
);
$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,
......@@ -154,12 +139,13 @@ 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.
$form['author'] = array(
'#type' => 'details',
'#access' => user_access('administer nodes'),
'#title' => t('Authoring information'),
'#collapsed' => TRUE,
'#group' => 'advanced',
......@@ -176,9 +162,10 @@ public function form(array $form, array &$form_state) {
),
),
'#weight' => 90,
'#optional' => TRUE,
);
$form['author']['name'] = array(
$form['uid'] = array(
'#type' => 'textfield',
'#title' => t('Authored by'),
'#maxlength' => 60,
......@@ -186,19 +173,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',
......@@ -209,18 +199,23 @@ public function form(array $form, array &$form_state) {
'js' => array(drupal_get_path('module', 'node') . '/node.js'),
),
'#weight' => 95,
'#optional' => TRUE,
);
$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);
......@@ -317,11 +312,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.
......@@ -424,15 +419,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);
......
......@@ -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);
}
......
......@@ -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');
}
......
......@@ -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->entityTypeId, $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.');
}
}
......
......@@ -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');
}
}
......@@ -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',
......
......@@ -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'));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment