DefaultWizard.php in Flexiform 8
File
contrib/wizard/src/Wizard/DefaultWizard.php
View source
<?php
namespace Drupal\flexiform_wizard\Wizard;
use Drupal\Core\DependencyInjection\ClassResolverInterface;
use Drupal\Core\Form\FormBuilderInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\ctools\Wizard\FormWizardBase;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\flexiform_wizard\Entity\Wizard as WizardEntity;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
class DefaultWizard extends FormWizardBase {
protected $wizard = NULL;
protected $provided = [];
public function __construct(PrivateTempStoreFactory $tempstore, FormBuilderInterface $builder, ClassResolverInterface $class_resolver, EventDispatcherInterface $event_dispatcher, RouteMatchInterface $route_match, WizardEntity $wizard, $step = NULL) {
parent::__construct($tempstore, $builder, $class_resolver, $event_dispatcher, $route_match, 'flexiform_wizard.' . $wizard
->id(), 'flexiform_wizard__' . $wizard
->id(), $step);
$this->wizard = $wizard;
$provided = [];
foreach ($this->wizard
->get('parameters') as $param_name => $param_info) {
if ($provided_entity = $route_match
->getParameter($param_name)) {
$provided[$param_name] = $provided_entity;
}
}
$this->provided = $provided;
}
public static function getParameters() {
return [
'tempstore' => \Drupal::service('user.private_tempstore'),
'builder' => \Drupal::service('form_builder'),
'class_resolver' => \Drupal::service('class_resolver'),
'event_dispatcher' => \Drupal::service('event_dispatcher'),
];
}
public function initValues() {
$values = parent::initValues();
$values['entities'] += $this->provided;
return $values;
}
public function getMachineName() {
return $this->wizard
->id();
}
public function getTempstore() {
return \Drupal::service('user.private_tempstore')
->get($this
->getTempstoreId());
}
public function getOperations($cached_values) {
$operations = [];
foreach ($this->wizard
->getPages() as $name => $page) {
$operations[$name] = [
'form' => 'Drupal\\flexiform_wizard\\Form\\DefaultWizardOperation',
'title' => $page['name'],
];
}
return $operations;
}
public function getRouteName() {
return 'flexiform_wizard.' . $this->wizard
->id() . '.step';
}
}