Problem/Motivation

The documentation at https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21fo... states (empahsis added):

The 'sandbox' array key is not initially set when this callback is first called, which makes it useful for determining whether it is the first call of the callback or not:

if (empty($context['sandbox'])) {

  // Perform set-up steps here.
}

The words contradict the example.

Steps to reproduce

  1. use batch_set in a form to create a batch
  2. inspect the incoming $context variable in the operation function

Expected behaviour from description: array_key_exists('sandbox', $context) === false
Current behaviour: array_key_exists('sandbox', $context) === true

Expected behaviour from example: empty($context['sandbox']) === true
Current behaviour: empty($context['sandbox']) === true

Proposed resolution

Update the documentation to indicate the array key is "empty" rather than "not set".

Remaining tasks

User interface changes

None

API changes

Documenttion only

Data model changes

None

Release notes snippet

None

Issue fork drupal-3307468

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

darvanen created an issue. See original summary.

darvanen’s picture

Status: Active » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Makes sense to me.

darvanen’s picture

Category: Task » Bug report
Issue tags: +Bug Smash Initiative

Three members of the bug smash initiative (myself, @smustgrave and @ambermatz) believe this to be a bug.

darvanen’s picture

Priority: Normal » Minor
alexpott’s picture

Title: Batch API documentation update » Improve Batch API $context['sandbox'] documentation
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 9514c30ab4 to 10.1.x and 92edba5344 to 10.0.x and f2edbcb391 to 9.5.x and f59520e3bc to 9.4.x. Thanks!

Backported to 9.4.x since this is a docs only change.

Changed the issue title to be a little tighter to the scope of the issue.

  • alexpott committed 9514c30 on 10.1.x
    Issue #3307468 by darvanen: Improve Batch API $context['sandbox']...

  • alexpott committed 92edba5 on 10.0.x
    Issue #3307468 by darvanen: Improve Batch API $context['sandbox']...

  • alexpott committed f2edbcb on 9.5.x
    Issue #3307468 by darvanen: Improve Batch API $context['sandbox']...

  • alexpott committed f59520e on 9.4.x
    Issue #3307468 by darvanen: Improve Batch API $context['sandbox']...

Status: Fixed » Closed (fixed)

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