Currently, when using the Wizard API, you can specify the same form class in multiple operations (in ::getOperations()), but all those steps will work identically.

To facilitate code reuse, it'd be great pass a set of overrides for the wizard's cached values when on a particular step. This way, you can use the same form class, but it'll operate on different data. You can even have the values be dependent on other dynamic data in the wizard!

Here's how it'd be used:

class MyWizard extends FormWizardBase {
  public function getOperations($cached_values) {
    return [
      'one' => [
        'title' => $this->t('Step One'),
        'form' => '\Drupal\my_module\StepForm',
        // On this step, $cached_values['value'] will equal 'one'.
        'values' => ['value' => 'one'],
      ],
      'two' => [
        'title' => $this->t('Step Two'),
        'form' => '\Drupal\my_module\StepForm',
        // On this step, $cached_values['value'] will equal 'two'.
        'values' => ['value' => 'two'],
      ],
    ];
  }
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dsnopek created an issue. See original summary.

dsnopek’s picture

Status: Active » Needs review
Issue tags: +Needs tests
FileSize
1.45 KB

Here's the initial patch! This needs tests.

dsnopek’s picture

Issue tags: -Needs tests
FileSize
5.14 KB

And here are some tests!

EclipseGc’s picture

Status: Needs review » Fixed

Great for page_manager and other such nuanced wizards.

Fixed

Eclipse

  • EclipseGc committed 9c3e7f4 on 8.x-3.x authored by dsnopek
    Issue #2616492 by dsnopek: Allow overriding cached values for specific...

Status: Fixed » Closed (fixed)

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