Problem/Motivation

drupal_form_submit() is marked deprecated for 8.0.

Allowed in beta?

per https://www.drupal.org/contribute/core/beta-changes

This function is already marked for deprecation before and after this patch:

/**
 * Retrieves, populates, and processes a form.
 *
 * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
 *   Use \Drupal::formBuilder()->submitForm().
 *
 * @see \Drupal\Core\Form\FormBuilderInterface::submitForm().
 */
function drupal_form_submit($form_arg, FormStateInterface $form_state) {

The only usages left are the function definition itself, and a reference in
core/scripts/generate-d7-content.sh
which is ok. That d7.sh script should not be touched. It is to be executed on a d7 site, so should be using the d7 api.

core/includes/form.inc
28:function drupal_form_submit($form_arg, FormStateInterface $form_state) {

core/scripts/generate-d7-content.sh
269:    drupal_form_submit('poll_view_voting', $form_state, $node);

Proposed resolution

Remove usage of drupal_form_submit(), including updating comments referencing drupal_form_submit() or drupal_prepare_form().

Remaining tasks

Make a child issue to actually remove the wrapper function from core.

User interface changes

No.

API changes

No.

Comments

shadik’s picture

Assigned: Unassigned » shadik
shadik’s picture

Status: Active » Needs review
StatusFileSize
new899 bytes

Status: Needs review » Needs work

The last submitted patch, 2: drupal_form_submit.patch, failed testing.

shadik’s picture

StatusFileSize
new1.05 KB
shadik’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 4: remove_usage_of-2367743-4.patch, failed testing.

shadik’s picture

Status: Needs work » Needs review
StatusFileSize
new760 bytes

Status: Needs review » Needs work

The last submitted patch, 7: remove_usage_of-2367743-5.patch, failed testing.

Miroling’s picture

StatusFileSize
new757 bytes
Miroling’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: remove_usage_of-2367743-6.patch, failed testing.

Miroling’s picture

Status: Needs work » Needs review
StatusFileSize
new883 bytes

Status: Needs review » Needs work

The last submitted patch, 12: remove_usage_of-2367743-12.patch, failed testing.

Miroling’s picture

Status: Needs work » Needs review
StatusFileSize
new6.25 KB

Status: Needs review » Needs work

The last submitted patch, 14: remove_usage_of-2367743-14.patch, failed testing.

Miroling’s picture

Status: Needs work » Needs review
StatusFileSize
new727 bytes
podarok’s picture

Status: Needs review » Reviewed & tested by the community

#16 looks good. RTBC

gumanist’s picture

Status: Reviewed & tested by the community » Needs work

please, update comments and usage in other files as well.

drupal/core/includes/batch.inc: // drupal_form_submit()), initialize a timer to determine whether we need to
drupal/core/includes/install.core.inc: * array that is passed on to the form submission via drupal_form_submit()).
drupal/core/includes/install.core.inc: // submission via drupal_form_submit().
drupal/core/lib/Drupal/Core/Form/FormBuilderInterface.php: * drupal_form_submit('mymodule_form', $form_state);
drupal/core/lib/Drupal/Core/Form/FormBuilderInterface.php: * drupal_form_submit('user_register_form', $form_state);
drupal/core/lib/Drupal/Core/Render/Element/Checkboxes.php: // should be unchecked; see drupal_form_submit(). We therefore remove all
drupal/core/modules/simpletest/src/InstallerTestBase.php: // suitable for a programmed drupal_form_submit().
drupal/core/modules/system/src/Tests/Batch/ProcessingTest.php: * Tests that drupal_form_submit() can run within a batch operation.
drupal/core/modules/system/src/Tests/Batch/ProcessingTest.php: $this->assertEqual(batch_test_stack(), array('mock form submitted with value = ' . $value), 'drupal_formdrupal/core/modules/system/tests/modules/batch_test/batch_test.module: * Batch operation: Submits form_test_mock_form() using drupal_form_submit().
drupal/core/modules/system/tests/modules/batch_test/batch_test.module:function _batch_test_nested_drupal_form_submit_callback($value) {
drupal/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php: array('_batch_test_nested_drupal_form_submit_callback', array($value)),
drupal/core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php: * drupal_form_submit().
drupal/core/scripts/generate-d7-content.sh: drupal_form_submit('poll_view_voting', $form_state, $node);

podarok’s picture

podarok’s picture

Miroling’s picture

Assigned: shadik » Miroling
rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new7.54 KB
yesct’s picture

Issue summary: View changes
Status: Needs review » Needs work

Evaluating per https://www.drupal.org/contribute/core/beta-changes

--

while looking at the patch, I saw a few things to change.
Patch coming.

yesct’s picture

  1. +++ b/core/includes/batch.inc
    @@ -218,8 +218,9 @@ function _batch_process() {
       // If this batch was marked for progressive execution (e.g. forms submitted by
    -  // drupal_form_submit()), initialize a timer to determine whether we need to
    -  // proceed with the same batch phase when a processing time of 1 second has
    +  // \Drupal::formBuilder()->submitForm(), initialize a timer to determine
    +  // whether we need to proceed with the same batch phase when a processing time
    +  // of 1 second has
       // been exceeded.
    

    the overflow should be merged with the partial line/comment.

  2. +++ b/core/modules/system/src/Tests/Batch/ProcessingTest.php
    @@ -129,14 +129,15 @@ function testBatchFormProgrammatic() {
    -   * Tests that drupal_form_submit() can run within a batch operation.
    +   * Tests that \Drupal::formBuilder()->submitForm() can run within a batch
    +   * operation.
    
    +++ b/core/modules/system/tests/modules/batch_test/batch_test.module
    @@ -8,7 +8,8 @@
    - * Batch operation: Submits form_test_mock_form() using drupal_form_submit().
    + * Batch operation: Submits form_test_mock_form() using
    + * \Drupal::formBuilder()->submitForm().
    

    one line summaries should stay one line (80 chars or less).

    "All summaries (first lines of docblocks) must be under 80 characters, start with a capital letter, and end with a period (.). They must provide a brief description of what a function does, what a class does, what a file contains, etc."

    https://www.drupal.org/node/1354#drupal

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new1.85 KB
new7.52 KB

Note, in this last one, form_test_mock_form() is an error, there is no such function anymore. It was removed in #2132477: Convert batch_test forms to controllers

I just reworded it this comment.

yesct’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/system/src/Tests/Batch/ProcessingTest.php
    @@ -129,14 +129,14 @@ function testBatchFormProgrammatic() {
    +   * Tests that \Drupal::formBuilder()->submitForm() within a batch operation.
    

    oops. now the grammar is off. Fix coming.

  2. +++ b/core/modules/system/tests/modules/batch_test/batch_test.module
    @@ -8,7 +8,7 @@
    - * Batch operation: Submits form_test_mock_form() using drupal_form_submit().
    

    I left this and did not change it to Third person verb since the other summaries in this test module use this form.

yesct’s picture

Assigned: Miroling » Unassigned
Status: Needs work » Needs review
StatusFileSize
new633 bytes
new7.52 KB
star-szr’s picture

Title: Remove usage of drupal_form_submit() » Remove usages of drupal_form_submit() and update documentation
Status: Needs review » Reviewed & tested by the community

I reviewed the patch with git diff --color-words (which I just found out works awesome when re-wrapping!) and it looks good from there.

I verified the grep from the issue summary and there are no remaining usages/docs updates needed.

Some of the docs are slightly reworded to fit in 80 characters but they make more sense and fix references to things that are gone now.

RTBC!

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

The existing change record should be updated to link to this issue.

rpayanm’s picture

Status: Needs work » Reviewed & tested by the community

Update the CR.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
@@ -95,12 +95,12 @@ public static function valueCallback(&$element, $input, FormStateInterface $form
+      // should be unchecked; see \Drupal::formBuilder()->submitForm(). We

I think this should be a link to \Drupal\Core\Form\FormBuilderInterface::submitForm() since I think the point here is to point the reader to the documentation there. In fact the correct thing might be to remove this and add an @see to the end of the doc block.

gaurav.pahuja’s picture

Status: Needs work » Needs review
StatusFileSize
new7.52 KB
new1.42 KB

Please review.

filijonka’s picture

Status: Needs review » Needs work

the @see shouldn't be added in the comment but to the docblock for the function per @alexpott comment

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.03 KB
new7.81 KB
David Hernández’s picture

Status: Needs review » Reviewed & tested by the community

The "@see" has been removed correctly from the code and now is part of the docblock from before the function.

yesct’s picture

I dont know if @alexpott really meant the end of the doc block /** ... */ on the method, or just at the end of the group of the in line comments.
... because I dont think our api parser, can parse @inheritdoc *AND* also additional documentation.

See #1994890-10: Allow {@inheritdoc} and additional documentation

filijonka’s picture

hi

wasn't aware of that we had an inherit doc so that's my fault but I also thought it was solved so we could use both inherit and a new tag, simply since I see it here and there. But apparently not.

anyway, the @see was on the end of the group of inline comments, and I'm not really sure what the point of using a @see on a inline comment is.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/lib/Drupal/Core/Render/Element/Checkboxes.php
    @@ -83,6 +83,8 @@ public static function processCheckboxes(&$element, FormStateInterface $form_sta
    +   * @see \Drupal::formBuilder()->submitForm()
    

    This should point to the interface.

  2. +++ b/core/modules/system/src/Tests/Batch/ProcessingTest.php
    @@ -129,14 +129,15 @@ function testBatchFormProgrammatic() {
    -   * Tests that drupal_form_submit() can run within a batch operation.
    +   * Tests that \Drupal::formBuilder()->submitForm() can run within a batch
    +   * operation.
    

    SHould be on one line... "Test form submission during a batch operation"

  3. +++ b/core/modules/system/tests/modules/batch_test/batch_test.module
    @@ -8,7 +8,8 @@
    + * Batch operation: Submits form_test_mock_form() using
    + * \Drupal::formBuilder()->submitForm().
    

    Should be on one line. "Batch operation: Submits form_test_mock_form()."

rpayanm’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB
new7.74 KB
filijonka’s picture

Status: Needs review » Needs work

Hi

see comment #36 about the @see tag. my fault but it won't work with current parser as @YesCT mentioned.

ianthomas_uk’s picture

Status: Needs work » Needs review
StatusFileSize
new1.35 KB
new7.48 KB

Moved the @see back to an inline comment but now pointing to the interface. Restored a line of the comment that had gone missing.

ianthomas_uk’s picture

Issue summary: View changes
StatusFileSize
new744 bytes
new8.21 KB

There's also a single mention of drupal_prepare_form() in a comment which we may as well fix here (the other form functions have already been removed).

prashant.c’s picture

Patch given in #42 applying succesfully and removing all the instances of drupal_form_submit() from

/core/includes/batch.inc:
./core/includes/install.core.inc:
./core/includes/install.core.inc:
./core/modules/system/tests/modules/batch_test/src/Controller/BatchTestController.php:
./core/modules/system/tests/modules/batch_test/batch_test.module:
./core/modules/system/src/Tests/Batch/ProcessingTest.php:
./core/modules/system/src/Tests/Batch/ProcessingTest.php:

and also removing instances of drupal_prepare_form().

rpayanm’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine for me.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue is a prioritized change (deprecated code removal) as per https://www.drupal.org/core/beta-changes and it's benefits outweigh any disruption. Committed ff41283 and pushed to 8.0.x. Thanks!

diff --git a/core/includes/batch.inc b/core/includes/batch.inc
index 8358816..362854d 100644
--- a/core/includes/batch.inc
+++ b/core/includes/batch.inc
@@ -214,8 +214,7 @@ function _batch_process() {
   // If this batch was marked for progressive execution (e.g. forms submitted by
   // \Drupal::formBuilder()->submitForm(), initialize a timer to determine
   // whether we need to proceed with the same batch phase when a processing time
-  // of 1 second has
-  // been exceeded.
+  // of 1 second has been exceeded.
   if ($batch['progressive']) {
     Timer::start('batch_processing');
   }

Fixed on commit.

  • alexpott committed ff41283 on 8.0.x
    Issue #2367743 by rpayanm, Miroling, YesCT, ianthomas_uk, shadik, gaurav...

Status: Fixed » Closed (fixed)

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