Problem/Motivation

The Remove from book outline button on the book outline form is labeled Delete and goes to the node delete form instead. This is due to the content entity form setting $actions['delete'] as a link rather than button, while the BookOutlineForm::actions() method expects it to be a button.

Proposed resolution

The patch in #2516930-11: Remove from outline button goes to node/x/delete instead replaces the link to node/x/delete with a link to node/x/outline/remove, and adds a test to ensure the link is present.

Remaining tasks

@alexpott in #2516930-12: Remove from outline button goes to node/x/delete instead asked for a test that clicks on the link, to have a test that actually does the same things a user would.

User interface changes

The link to node/x/outline/remove will be restored: this matches the workflow in Drupal 7. No string changes.

API changes

Form structure is considered @internal. Removing a node from a book no longer triggers the form validation handlers, but this is desired behavior as of #216064: Entity form "Delete" button triggers server-side + HTML5 form validation; change "Delete" button to a link.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhedstrom’s picture

jhedstrom’s picture

The last submitted patch, 1: book-outline-remove-2516930-01-TEST-ONLY.patch, failed testing.

drcho’s picture

I can confirm this issue on Drupal-8-beta-12. In addition it isn't possible to remove a node from books in the form display of the node.

Book Outline in Form Display

jhedstrom’s picture

coleman.sean.c’s picture

I was pointed here from #2650756: [Regression] No UI to remove nodes from books., which I've just closed as a duplicate. I took a slightly different approach, and replaced the button with a link to node/x/outline/remove. Here's my reasoning:

  • $actions['delete'] in EntityForm was turned into a link as part of #216064: Entity form "Delete" button triggers server-side + HTML5 form validation; change "Delete" button to a link. The reason behind that change was that delete buttons trigger form validation, whereas the delete link does not. I think that argument applies to the 'Remove from outline' operation.
  • Using a delete link instead of a delete button adds a confirmation step, which matches the workflow from Drupal 7.
  • Nothing in core uses the entity.node.book_remove_form route. It appears that \Drupal\book\Form\BookRemoveForm is dead code, in the sense that it is not linked from anywhere in the UI.

Of course either fix would be better than what we have currently. If you've got a counter-argument, I'd be happy to RTBC this approach instead.

coleman.sean.c’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
41.6 KB
44.19 KB
33.44 KB

Apologies: I've just run this through simplytest.me, and that's exactly what this patch does. Screenshots attached.

RTBC!

catch’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.77 KB

Re-uploading a patch, can't see another way to get it through the new bots.

mcjim’s picture

Status: Needs review » Reviewed & tested by the community

Tested manually, works as described. Code makes sense. \o/

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/book/src/Form/BookOutlineForm.php
@@ -91,8 +91,14 @@ public function form(array $form, FormStateInterface $form_state) {
+    $actions['delete']['#type'] = 'submit';

@coleman.sean.c is correct that this should be a link and not a submit button for the reasons given in #6. The BookOutlineForm::delete() method should be removed and we should just make a link to the book-remove-form.

coleman.sean.c’s picture

Attached patch removes the delete method, and replaces the button with a link, as per @alexpott in #10.

Since the delete button is no longer part of the form, drupalPostForm can't be used to click it, and the test-only patch from #1 won't pass. Instead, I've used assertLink: Is that sufficient?

The last submitted patch, 11: book_remove_form-2516930-11-test-only.patch, failed testing.

alexpott’s picture

Status: Needs review » Needs work

Looking good.

+++ b/core/modules/book/src/Tests/BookTest.php
@@ -583,6 +584,7 @@ public function testBookOutline() {
+    $this->assertLink(t('Remove from book outline'));

It'd be good to click the link here and do the delete and confirm that this has worked. Yes this the functionality of the delete form is tested elsewhere but it would be good to have a test that actually does the same things as a user would.

coleman.sean.c’s picture

Okay.

I won't have time to work on this for a few weeks, so if someone wants to write that test, please feel free.

coleman.sean.c’s picture

Issue summary: View changes
mohit_aghera’s picture

Status: Needs work » Needs review
FileSize
31.93 KB
684 bytes

Status: Needs review » Needs work

The last submitted patch, 16: book_remove_form-2516930-12.patch, failed testing.

alexpott’s picture

Not sure what's happened in #16. I suspect it reverted some changes...

Here's a new patch with the clickLink() and an assert to make sure we've ended up on the right page. There's no point actually removing the book from the outline as that is tested elsewhere.

The last submitted patch, 18: 2516930-18.test-only.patch, failed testing.

mohit_aghera’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
72.48 KB

Tested issue by applying patch.
Looks good. Redirects to node/nid/outline/remove page.

  • catch committed 315bc18 on 8.1.x
    Issue #2516930 by coleman.sean.c, alexpott, jhedstrom, mohit_aghera:...

  • catch committed df9a3c4 on 8.0.x
    Issue #2516930 by coleman.sean.c, alexpott, jhedstrom, mohit_aghera:...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.