Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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'],
],
];
}
}
Comment | File | Size | Author |
---|---|---|---|
#3 | ctools-operations-values-2616492-3.patch | 5.14 KB | dsnopek |
Comments
Comment #2
dsnopekHere's the initial patch! This needs tests.
Comment #3
dsnopekAnd here are some tests!
Comment #4
EclipseGc CreditAttribution: EclipseGc commentedGreat for page_manager and other such nuanced wizards.
Fixed
Eclipse