diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index c4ebe28..a108dc7 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -117,6 +117,8 @@ protected function actionsElement(array $form, array &$form_state) { * Returns an array of supported actions for the current entity form. */ protected function actions(array $form, array &$form_state) { + $info = entity_get_info($form['#entity_type']); + return array( // @todo Rename the action key from submit to save. 'submit' => array( @@ -132,6 +134,8 @@ protected function actions(array $form, array &$form_state) { 'delete' => array( '#value' => t('Delete'), // No need to validate the form when deleting the entity. + // Keep the entity id key for passing id of the entity to delete confirmation form + '#limit_validation_errors' => array(array($info['entity keys']['id'])), '#submit' => array( array($this, 'delete'), ), diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php index b4cd7e7..11031e8 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuTest.php @@ -75,6 +75,20 @@ function testMenu() { // Delete custom menu. $this->deleteCustomMenu($this->menu); + // Delete menu submitting empty title on edit form. Check if validation permits to do this. + $menu_name = substr(hash('sha256', $this->randomName(16)), 0, MENU_MAX_MENU_NAME_LENGTH_UI); + $title = $this->randomName(16); + + $menu = array( + 'menu_name' => $menu_name, + 'title' => $title, + 'description' => 'Description text', + ); + menu_save($menu); + $edit = array('title' => ''); + $this->drupalPost('admin/structure/menu/manage/' . $menu_name . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))), t('Delete menu on edit form with empty title.')); + // Modify and reset a standard menu link. $item = $this->getStandardMenuLink(); $old_title = $item['link_title']; @@ -87,6 +101,33 @@ function testMenu() { $saved_item = menu_link_load($item['mlid']); $this->assertEqual($description, $saved_item['options']['attributes']['title'], 'Saving an existing link updates the description (title attribute)'); $this->resetMenuLink($item, $old_title); + // Delete link submitting empty title or path on edit form. Check if validation permits to do this. + // Login the user. + $this->drupalLogin($this->big_user); + // Create custom link to User menu. + $link_title = $this->randomName(); + $edit = array( + 'link_title' => $link_title, + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/manage/user-menu/add', $edit, t('Save')); + // Select mlid of new created menu item. + $mlid = db_query("SELECT mlid FROM {menu_links} WHERE link_title = :link_title", array(':link_title' => $link_title))->fetchField(); + // Submit edit form with empty title. + $edit = array( + 'link_title' => '', + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/item/' . $mlid . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Menu link title'))), t('Delete link on edit form with empty title.')); + + // Submit edit form with empty path. + $edit = array( + 'link_title' => $link_title, + 'link_path' => '', + ); + $this->drupalPost('admin/structure/menu/item/' . $mlid . '/edit', $edit, t('Delete')); + $this->assertNoText(t('!name field is required.', array('!name' => t('Path'))), t('Delete link on edit form with empty path.')); } /** diff --git a/core/modules/menu/menu.admin.inc b/core/modules/menu/menu.admin.inc index fc38caa..ed2ded5 100644 --- a/core/modules/menu/menu.admin.inc +++ b/core/modules/menu/menu.admin.inc @@ -319,6 +319,8 @@ function menu_edit_item($form, &$form_state, $type, $item, $menu) { '#access' => $item['mlid'], '#submit' => array('menu_item_delete_submit'), '#weight' => 10, + // Keep array('mlid') for passing mlid of the menu link item to delete confirmation form. + '#limit_validation_errors' => array(array('mlid')), ); } else { @@ -512,6 +514,9 @@ function menu_edit_menu($form, &$form_state, $type, $menu = array()) { '#value' => t('Delete'), '#access' => $type == 'edit' && !isset($system_menus[$menu['menu_name']]), '#submit' => array('menu_custom_delete_submit'), + // Keep array('menu_name') for passing menu_name of the + // menu item to delete confirmation form. + '#limit_validation_errors' => array(array('menu_name')), ); return $form; diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeDeletionTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeDeletionTest.php new file mode 100644 index 0000000..b9bf680 --- /dev/null +++ b/core/modules/node/lib/Drupal/node/Tests/NodeDeletionTest.php @@ -0,0 +1,61 @@ + 'Node deletion', + 'description' => 'Create a node and test node delete functionality.', + 'group' => 'Node', + ); + } + + function setUp() { + parent::setUp(); + + $this->web_user = $this->drupalCreateUser(array( + 'edit own page content', 'create page content', 'delete own page content' + )); + } + + /** + * Check deleting node from edit form with empty title. + */ + function testNodeDeleteEmptyTitle() { + $this->drupalLogin($this->web_user); + + $langcode = LANGUAGE_NOT_SPECIFIED; + $title_key = "title"; + $body_key = "body[$langcode][0][value]"; + // Create node to delete. + $edit = array(); + $edit[$title_key] = $this->randomName(8); + $edit[$body_key] = $this->randomName(16); + $this->drupalPost('node/add/page', $edit, t('Save')); + + // Load created node. + $node = $this->drupalGetNodeByTitle($edit[$title_key]); + + // Delete the node through edit form. + $edit = array(); + $edit[$title_key] = ''; + $edit[$body_key] = $this->randomName(16); + // Use Delete button on edit form taking off the title. + $this->drupalPost("node/$node->nid/edit", $edit, t('Delete')); + + // Check that node edit form can be submitted + // with Delete button and empty title. + $this->assertNoText(t('!name field is required.', array('!name' => t('Title'))), t('Delete button works with empty title on edit form.')); + } +} \ No newline at end of file diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc index 4188eff..91862f0 100644 --- a/core/modules/path/path.admin.inc +++ b/core/modules/path/path.admin.inc @@ -189,6 +189,8 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali '#type' => 'submit', '#value' => t('Delete'), '#submit' => array('path_admin_form_delete_submit'), + // Keep array('pid') for passing pid of the url alias record to delete confirmation form. + '#limit_validation_errors' => array(array('pid')), ); } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php index 6e0153c..d3152dd 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRoleAdminTest.php @@ -56,8 +56,9 @@ function testRoleAdministration() { $new_role = user_role_load($old_name); $this->assertEqual($new_role->name, $role_name, 'The role name has been successfully changed.'); - // Test deleting a role. - $this->drupalPost("admin/people/roles/edit/{$role->rid}", NULL, t('Delete role')); + // Test deleting a role with empty role name. + $edit = array('role[name]' => ''); + $this->drupalPost("admin/people/roles/edit/{$role->rid}", $edit, t('Delete role')); $this->drupalPost(NULL, NULL, t('Delete')); $this->assertText(t('The role has been deleted.'), t('The role has been deleted')); $this->assertNoLinkByHref("admin/people/roles/edit/{$role->rid}", t('Role edit link removed.')); diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 180b9f1..076dc30 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -1025,6 +1025,8 @@ function user_admin_role($form, $form_state, $role) { '#value' => t('Delete role'), '#access' => !empty($role->rid) && !in_array($role->rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID)), '#submit' => array('user_admin_role_delete_submit'), + // Keep array('rid') for passing rid of the role to delete confirmation form + '#limit_validation_errors' => array(array('role', 'rid')), ); return $form;