Multistep pages should not have random generated names

refs #6136
This commit is contained in:
Johannes Meyer 2014-05-14 09:01:24 +02:00
parent 51bac035ac
commit 429e09aae2
3 changed files with 33 additions and 46 deletions

View File

@ -4,7 +4,6 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Web\Session; use Icinga\Web\Session;
use Icinga\Web\Wizard\Page;
use Icinga\Web\Wizard\Wizard; use Icinga\Web\Wizard\Wizard;
use Icinga\Web\Controller\ActionController; use Icinga\Web\Controller\ActionController;
@ -36,12 +35,14 @@ class InstallController extends ActionController
$wizard = $this->createWizard(); $wizard = $this->createWizard();
$wizard->navigate(); // Needs to be called before isSubmittedAndValid() as this creates the form $wizard->navigate(); // Needs to be called before isSubmittedAndValid() as this creates the form
if ($wizard->isSubmittedAndValid() && $wizard->isFinished()) { if ($wizard->isSubmittedAndValid()) {
// TODO: Run the installer (Who creates an installer? How do we handle module installers?) if ($wizard->isFinished()) {
$this->dropConfiguration(); // TODO: Should only be done if the installation has been successfully completed // TODO: Run the installer (Who creates an installer? How do we handle module installers?)
$this->view->installer = ''; $this->dropConfiguration(); // TODO: Should only be done if the installation has been successfully completed
} else { $this->view->installer = '';
$this->storeConfiguration($wizard->getConfig()); } else {
$this->storeConfiguration($wizard->getConfig());
}
} }
$this->view->wizard = $wizard; $this->view->wizard = $wizard;
@ -60,14 +61,14 @@ class InstallController extends ActionController
$wizard->setConfiguration($this->loadConfiguration()); $wizard->setConfiguration($this->loadConfiguration());
$wizard->addPages( $wizard->addPages(
array( array(
'1st step' => new Page(), // t('Welcome') => 'Icinga\Form\Install\WelcomePage',
'2nd step' => new Page(), // t('Requirements') => 'Icinga\Form\Install\RequirementsPage',
'3rd step' => new Page(), // t('Authentication') => 'Icinga\Form\Install\AuthenticationPage',
'a wizard' => array( // t('Administration') => 'Icinga\Form\Install\AdministrationPage',
'4th step' => new Page(), // t('Preferences') => 'Icinga\Form\Install\PreferencesPage',
'5th step' => new Page() t('Logging') => 'Icinga\Form\Install\LoggingPage',
), // t('Database Setup') => 'Icinga\Form\Install\DatabasePage',
'last step' => new Page() // t('Summary') => 'Icinga\Form\Install\SummaryPage'
) )
); );

View File

@ -22,6 +22,14 @@ class Page extends Form
*/ */
protected $title = ''; protected $title = '';
/**
* Overwrite this to initialize this wizard page
*/
public function init()
{
}
/** /**
* Set the title for this wizard page * Set the title for this wizard page
* *

View File

@ -41,16 +41,18 @@ class Wizard extends Page
*/ */
public function addPage(Page $page) public function addPage(Page $page)
{ {
$ident = $this->generatePageIdentifier($page); if (!($pageName = $page->getName())) {
$wizardConfig = $this->getConfig(); throw new ProgrammingError('Wizard page "' . get_class($page) . '" has no unique name');
if ($wizardConfig->get($ident) === null) {
$wizardConfig->{$ident} = new Zend_Config(array(), true);
} }
$page->setTokenDisabled(); // Usually default for pages, but not for wizards $wizardConfig = $this->getConfig();
$page->setConfiguration($wizardConfig->{$ident}); if ($wizardConfig->get($pageName) === null) {
$wizardConfig->{$pageName} = new Zend_Config(array(), true);
}
$page->setConfiguration($wizardConfig->{$pageName});
$page->setRequest($this->getRequest()); $page->setRequest($this->getRequest());
$page->setName($ident); $page->setTokenDisabled(); // Usually default for pages, but not for wizards
$this->pages[] = $page; $this->pages[] = $page;
} }
@ -263,30 +265,6 @@ class Wizard extends Page
$config->{$currentPage->getName()} = $currentPage->getConfig(); $config->{$currentPage->getName()} = $currentPage->getConfig();
} }
/**
* Return a unique identifier for the given page
*
* @param Page $page The page for which to return the identifier
*
* @return string The page's unique identifier
*/
protected function generatePageIdentifier(Page $page)
{
if (($name = $page->getName())) {
return $name;
}
$pageClass = get_class($page);
$wizardConfig = $this->getConfig();
if ($wizardConfig->get('page_names') === null || $wizardConfig->page_names->get($pageClass) === null) {
$wizardConfig->page_names = $wizardConfig->get('page_names', new Zend_Config(array(), true));
$wizardConfig->page_names->{$pageClass} = sprintf('%06x', mt_rand(0, 0xffffff));
}
return $wizardConfig->page_names->{$pageClass};
}
/** /**
* Setup the current wizard page * Setup the current wizard page
*/ */