Problem/Motivation

If a submit handler sets a batch process, all the following submit handlers are queued as batch sets to be executed after that the batch process has completed. If a submit handler is defined in a conditionally included file, the following code might not work:

<?php
function _batch_next_set() {
  $batch = &batch_get();
  if (isset($batch['sets'][$batch['current_set'] + 1])) {
    $batch['current_set']++;
    $current_set = &_batch_current_set();
    if (isset($current_set['form_submit']) && ($function = $current_set['form_submit']) && function_exists($function)) {
      // We use our stored copies of $form and $form_state to account for
      // possible alterations by previous form submit handlers.
      $function($batch['form_state']['complete form'], $batch['form_state']);
    }
    return TRUE;
  }
}
?>

Since the file holding the submit handler may have been included in the original page request but not while processing the batch. In this case the submit handler will be skipped silently.

To reproduce this just set a batch from a submit handler acting before another one living in a not always included file, e.g. field_ui_field_settings_form_submit().

Proposed resolution

Find a way to store the parent file alongside with the submit handler, in order to include it before verifying that the submit handler is actually available.

Remaining tasks

  • Find an agreement on the solution
  • Write a patch
  • Review and test the patch

User interface changes

None

API changes

None

Comments

plach’s picture

Issue tags: +Needs backport to D7
JeremyFrench’s picture

I think that it should be possible to include files (more than one) in batch_set, that should be a fairly simple way to provide a mechanism for avoiding this bug.

I'm not sure if the framework should try and handle this automatically.

plach’s picture

@JeremyFrench:

Not sure about this: in the case above we'd have to explicitly set the include file(s) where the submit handler(s) live in. If any piece of code added more submit handlers we would have no way to make them work, not knowing anything about them.

chx’s picture

Assigned: Unassigned » chx
Damien Tournoud’s picture

Status: Active » Closed (works as designed)

You would have the same problem with, for example, submitting the form via an AJAX request (that submits to system/js.

It's your job to define the files used for the validation / submit handlers in $form_state['build_info']['files'].

sun’s picture

plach’s picture

Guys, I won't reopen this but in the ET code we had to explcitly include the core submit handler not ours: see #1279372-15: Enable bulk field language updates when switching field translatability around the end of the comment.

sun’s picture

Priority: Major » Normal
Status: Closed (works as designed) » Postponed (maintainer needs more info)

Can you provide an isolated test case for this?

I looked through the code you referenced and also field_ui, form and batch processing in HEAD, and can't see why field_ui.admin.inc wouldn't be included.

chx’s picture

Assigned: chx » Unassigned

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

pameeela’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)
Issue tags: +Bug Smash Initiative

Confirmed with plach this can be closed.