function WizardFactory::createWizard

Same name in other branches
  1. 8.x-3.x src/Wizard/WizardFactory.php \Drupal\ctools\Wizard\WizardFactory::createWizard()

Create form wizard.

Parameters

string $class: A class name implementing FormWizardInterface.

array $parameters: The array of parameters specific to this wizard.

Return value

\Drupal\ctools\Wizard\FormWizardInterface Return form Wizard.

Overrides WizardFactoryInterface::createWizard

File

src/Wizard/WizardFactory.php, line 84

Class

WizardFactory
The wizard factory.

Namespace

Drupal\ctools\Wizard

Code

public function createWizard($class, array $parameters) {
    $arguments = [];
    $reflection = new \ReflectionClass($class);
    $constructor = $reflection->getMethod('__construct');
    foreach ($constructor->getParameters() as $parameter) {
        if (array_key_exists($parameter->name, $parameters)) {
            $arguments[] = $parameters[$parameter->name];
        }
        elseif ($parameter->isDefaultValueAvailable()) {
            $arguments[] = $parameter->getDefaultValue();
        }
    }
    
    /** @var \Drupal\ctools\Wizard\FormWizardInterface $wizard */
    $wizard = $reflection->newInstanceArgs($arguments);
    return $wizard;
}