Updated: Comment #N

Problem/Motivation

ConfirmFormInterface::getCancelRoute() should only return \Drupal\Core\Url objects, but it can return either that or arrays right now, and is only documented to return arrays.

Proposed resolution

Switch getCancelRoute() to always return objects, and remove the array handling code from ConfirmFormHelper.

This is consistent with the changes to $form_state['redirect_route'] and $entity->urlInfo().

Remaining tasks

N/A

User interface changes

N/A

API changes

getCancelRoute() can no longer return arrays, only \Drupal\Core\Url objects

Comments

tim.plunkett’s picture

StatusFileSize
new2.18 KB

Status: Needs review » Needs work

The last submitted patch, 1: confirm-form-2226871-1.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review

1: confirm-form-2226871-1.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 1: confirm-form-2226871-1.patch, failed testing.

dawehner’s picture

  1. +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
    @@ -82,6 +83,28 @@ public function testCancelLinkRouteWithParams() {
       /**
    +   * Tests a cancel link route with a URL object.
    +   */
    

    Is there a reason to not actually use @covers ?

  2. +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php
    @@ -82,6 +83,28 @@ public function testCancelLinkRouteWithParams() {
    +    $cancel_route = new Url(
    +      'foo_bar/{baz}', array(
    +        'baz' => 'banana',
    +      ),
    +      array(
    +        'html' => TRUE,
    +      )
    

    This is NOT a valid route name. HTML also does not make sense on an URL object.

tim.plunkett’s picture

StatusFileSize
new2.56 KB
new3.79 KB

1) Because this was written before we were using @covers.
2) Copy/paste. Fixed throughout

tim.plunkett’s picture

Status: Needs work » Needs review
tim.plunkett’s picture

Title: Add test coverage for ConfirmFormInterface::getCancelRoute() returning Drupal\Core\Url » ConfirmFormInterface::getCancelRoute() should always return Drupal\Core\Url
Issue summary: View changes
StatusFileSize
new53.35 KB

Let's just repurpose this, no sense in breaking it up.

Status: Needs review » Needs work

The last submitted patch, 8: confirm-getcancelroute-2226871-8.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Needs review
StatusFileSize
new59.61 KB
new6.26 KB
sun’s picture

Issue tags: +API clean-up

Hm. I wanted to RTBC this, but then I noticed that a positive/successful form submission uses getCancelRoute() as the redirect target...

It basically re-purposes getCancelRoute() to not only be the route for the "Cancel" link, but also the route for a successful operation? That seems a little bit weird, no? Or is that documented somewhere?

Would it make sense to simply add a new getRedirectRoute() method to the base class that - by default - internally calls into getCancelRoute(), but which essentially ensures that the two (vastly different) conditions are properly covered in the public API?

tim.plunkett’s picture

Judging by the ones I converted, I'd say that only 2/3 of the classes use the same route for cancel and submit.
It's just a matter of convenience, I don't think that its harmful, and I definitely don't think it's worth adding Yet Another Method for.

tim.plunkett’s picture

I should also note, almost none of these classes have parent::submitForm(), so it would not be as easy as putting it into the base class. I think this is fine as is, and is a pattern that exists in HEAD.

tim.plunkett’s picture

StatusFileSize
new60.12 KB

Rerolled.

tim.plunkett’s picture

sun’s picture

Status: Needs review » Reviewed & tested by the community

Oh sorry, I missed that this is not a default/automation - just some classes are internally calling their own method to… not duplicate code (?), I guess.

My comment in #11 would only make sense if there was an automated default route, in which case it would be weird if the redirect route after successful submission would default to the cancel route.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Down with ArrayPIs! :P

Committed and pushed to 8.x. Thanks!

  • Commit 783bc94 on 8.x by webchick:
    Issue #2226871 by tim.plunkett: ConfirmFormInterface::getCancelRoute()...

Status: Fixed » Closed (fixed)

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