public function WizardFactory::getFormState in Chaos Tool Suite (ctools) 8.3
Get the wizard form state.
Parameters
\Drupal\ctools\Wizard\FormWizardInterface $wizard: The form wizard.
array $parameters: The array of parameters specific to this wizard.
bool $ajax: Is ajax or not.
Return value
\Drupal\Core\Form\FormState Return the form state.
Overrides WizardFactoryInterface::getFormState
1 call to WizardFactory::getFormState()
- WizardFactory::getWizardForm in src/
Wizard/ WizardFactory.php - Get the wizard form.
File
- src/
Wizard/ WizardFactory.php, line 114
Class
- WizardFactory
- The wizard factory.
Namespace
Drupal\ctools\WizardCode
public function getFormState(FormWizardInterface $wizard, array $parameters, $ajax = FALSE) {
$form_state = new FormState();
// If a wizard has no values, initialize them.
if (!$wizard
->getMachineName() || !$wizard
->getTempstore()
->get($wizard
->getMachineName())) {
$cached_values = $wizard
->initValues();
// Save the cached values that were initialized.
if ($wizard
->getMachineName()) {
$wizard
->getTempstore()
->set($wizard
->getMachineName(), $cached_values);
}
}
else {
$cached_values = $wizard
->getTempstore()
->get($wizard
->getMachineName());
}
$form_state
->setTemporaryValue('wizard', $cached_values);
$form_state
->set('ajax', $ajax);
$parameters['form'] = [];
$parameters['form_state'] = $form_state;
$method = new \ReflectionMethod($wizard, 'buildForm');
$arguments = [];
foreach ($method
->getParameters() as $parameter) {
if (array_key_exists($parameter->name, $parameters)) {
$arguments[] = $parameters[$parameter->name];
}
elseif ($parameter
->isDefaultValueAvailable()) {
$arguments[] = $parameter
->getDefaultValue();
}
}
unset($parameters['form'], $parameters['form_state']);
// Remove $form and $form_state from the arguments, and re-index them.
unset($arguments[0], $arguments[1]);
$form_state
->addBuildInfo('args', array_values($arguments));
return $form_state;
}