Similar to the new SystemConfigFormBase replacing system_config_form(), Crell suggested a replacement for confirm_form().

I present the creatively-named ConfirmFormBase!

The method names need a good deal of improvement. But here it is with two conversions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

webchick’s picture

Status: Active » Needs review

Neato.

Crell’s picture

+++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php
@@ -0,0 +1,96 @@
+  /**
+   * @todo.
+   */
+  abstract protected function getQuestion();

These should have an interface to define them, then the base class just to provide reasonable defaults.

+++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php
@@ -0,0 +1,96 @@
+  public function validateForm(array &$form, array &$form_state) {
+  }
+
+  public function submitForm(array &$form, array &$form_state) {

submitForm is required, so I wouldn't even define it here. The class is abstract so just go ahead and leave it out, so PHP will force implementers to add it. valdateForm I suppose makes sense to give a default-null implementation to, but submitForm should always need an implementation.

+++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php
@@ -0,0 +1,96 @@
+  /**
+   * @todo.
+   */
+  abstract protected function getQuestion();

This could use a ConfirmFormInterface to define the methods and documentation, then the base class for ease of implementation.

I love how we don't need to change anything in FAPI itself for this. OO++ :-)

tim.plunkett’s picture

Assigned: Unassigned » tim.plunkett
FileSize
4.61 KB
9.87 KB

Okay, this should address all of Crell's feedback, as well as improve the method names.

The interface still needs docs.

Status: Needs review » Needs work

The last submitted patch, confirm-form-1938600-3.patch, failed testing.

tim.plunkett’s picture

Now I remember why I didn't bother with an interface! None of these methods need to be public, and interfaces cannot contain protected methods.

So we have two options:

  1. Make the methods public for no reason other than to have them in an interface
  2. Leave them in an abstract base class that's you'd need to use 100% of the time to see any benefit anyway?
Crell’s picture

Bah, I didn't even notice that they were protected! Yeah, then I guess no interface, just the base class. Oh well.

tim.plunkett’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests
FileSize
4.99 KB
10.42 KB

There are no explicit tests for confirm_form() at all. With one conversion done here, we have implicit coverage, but we need to add some.

This goes back to the base class, with added docs and whatnot. Interdiff is against the OP, not #3.

Crell’s picture

+++ b/core/lib/Drupal/Core/Form/ConfirmFormBase.php
@@ -0,0 +1,122 @@
+  /**
+   * Returns the page to go to if the user cancels the action.
+   *
+   * @return string|array
+   *   This can be either:
+   *   - A string containing a Drupal path.
+   *   - An associative array with a 'path' key. Additional array values are
+   *     passed as the $options parameter to l().
+   *   If the 'destination' query parameter is set in the URL when viewing a
+   *   confirmation form, that value will be used instead of this path.
+   */
+  abstract protected function getPath();

getPath() doesn't suggest that it's the cancellation path. I'd rename this to getCancellationPath() or similar for clarity.

Otherwise, this is looking awesome.

tim.plunkett’s picture

Assigned: tim.plunkett » Unassigned
Issue tags: -Needs tests
FileSize
10.59 KB
17.36 KB

Good suggestion, I made that mistake when writing tests (I briefly thought it would control the $form_state['redirect'].

I'd say this is done. None of the other confirmation forms have been converted to FormInterface yet anyway, now they can go straight into this.

tim.plunkett’s picture

Issue tags: +FormInterface

Lost a tag somewhere.

Crell’s picture

Status: Needs review » Reviewed & tested by the community

+1 and pass the sweet potatoes.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

I had a longer review and then Chrome pinballed of death on me so I lost it. :(

Suffice to say, this patch looks awesome. I've always found confirm_form()'s "API" (big air quotes there) really confusing. It's so great to have consistency in our form definitions, despite the fact that the OO requirement of page controllers make me cranky. ;)

Committed and pushed to 8.x. Thanks!

xjm’s picture

Title: Add a FormInterface replacement for confirm_form() » [Change notice] Add a FormInterface replacement for confirm_form()
Priority: Normal » Critical
Status: Fixed » Active
Issue tags: +Needs change record

I think? Probably can update the existing one.

jibran’s picture

Title: [Change notice] Add a FormInterface replacement for confirm_form() » Change notice: Add a FormInterface replacement for confirm_form()

Will there be a meta issue to convert all the confirm form?
Related #1842036: [META] Convert all confirm forms to use modal dialog.

tim.plunkett’s picture

tim.plunkett’s picture

Status: Active » Needs review

Here's the change notice: http://drupal.org/node/1945416

jibran’s picture

Title: Change notice: Add a FormInterface replacement for confirm_form() » Add a FormInterface replacement for confirm_form()
Priority: Critical » Normal
Status: Needs review » Fixed
Issue tags: -Needs change record

Change notice looks good thanks.

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