PageWizardBase.php in Page Manager 8.4
File
page_manager_ui/src/Wizard/PageWizardBase.php
View source
<?php
namespace Drupal\page_manager_ui\Wizard;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\ctools\Wizard\EntityFormWizardBase;
use Drupal\page_manager_ui\Access\PageManagerPluginAccess;
use Drupal\page_manager_ui\Form\PageGeneralForm;
use Drupal\page_manager_ui\Form\PageParametersForm;
use Drupal\page_manager_ui\Form\PageAccessForm;
class PageWizardBase extends EntityFormWizardBase {
public function initValues() {
$cached_values = parent::initValues();
$cached_values['access'] = new PageManagerPluginAccess();
return $cached_values;
}
public function getEntityType() {
return 'page';
}
public function exists() {
return '\\Drupal\\page_manager\\Entity\\Page::load';
}
public function getWizardLabel() {
return $this
->t('Page Manager');
}
public function getMachineLabel() {
return $this
->t('Administrative title');
}
public function getOperations($cached_values) {
$operations = [];
$operations['general'] = [
'title' => $this
->t('Page information'),
'form' => PageGeneralForm::class,
];
$page = $cached_values['page'];
if ($page) {
$matches = [];
preg_match_all('|\\{\\w+\\}|', $page
->getPath(), $matches);
if (array_filter($matches)) {
$operations['parameters'] = [
'title' => $this
->t('Page parameters'),
'form' => PageParametersForm::class,
];
}
}
$operations['access'] = [
'title' => $this
->t('Page access'),
'form' => PageAccessForm::class,
];
return $operations;
}
public function submitVariantStep(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
$page_variant = $cached_values['page_variant'];
$plugin = $cached_values['plugin'];
if (!empty($plugin) && !empty($page_variant)) {
$page_variant
->getVariantPlugin()
->setConfiguration($plugin
->getConfiguration());
}
}
public function finish(array &$form, FormStateInterface $form_state) {
parent::finish($form, $form_state);
$cached_values = $form_state
->getTemporaryValue('wizard');
$page = $cached_values['page'];
foreach ($page
->getVariants() as $variant) {
$variant
->save();
}
$form_state
->setRedirectUrl(new Url('entity.page.edit_form', [
'machine_name' => $this->machine_name,
'step' => 'general',
]));
}
}