Multistep pages should know about their multistep form

refs #6136
This commit is contained in:
Johannes Meyer 2014-05-14 12:42:22 +02:00
parent 1f942acd38
commit 754f854dd0
2 changed files with 43 additions and 6 deletions

View File

@ -15,6 +15,13 @@ class Page extends Form
*/
protected $tokenDisabled = true;
/**
* The wizard this page is part of
*
* @var Wizard
*/
protected $wizard;
/**
* The title of this wizard page
*
@ -22,6 +29,18 @@ class Page extends Form
*/
protected $title = '';
/**
* Create a new wizard page
*
* @param Wizard $wizard The wizard this page is part of
* @param mixed $options Zend_Form options
*/
public function __construct(Wizard $wizard = null, $options = null)
{
parent::__construct($options);
$this->wizard = $wizard;
}
/**
* Overwrite this to initialize this wizard page
*/

View File

@ -34,6 +34,27 @@ class Wizard extends Page
return $this->pages;
}
/**
* Return a page by its name or null if it's not found
*
* @param string $pageName The name of the page
*
* @return Page|null
*/
public function getPage($pageName)
{
$candidates = array_filter(
$this->pages, // Cannot use getPages() here because I might get called as part of Page::isRequired()
function ($page) use ($pageName) { return $page->getName() === $pageName; }
);
if (!empty($candidates)) {
return array_shift($candidates);
} elseif ($this->wizard !== null) {
return $this->wizard->getPage($pageName);
}
}
/**
* Add a new page to this wizard
*
@ -68,17 +89,14 @@ class Wizard extends Page
{
foreach ($pages as $title => $pageClassOrArray) {
if (is_array($pageClassOrArray)) {
$wizard = new static();
$wizard = new static($this);
$wizard->setTitle($title);
$this->addPage($wizard);
$wizard->addPages($pageClassOrArray);
} elseif (is_string($pageClassOrArray)) {
$page = new $pageClassOrArray();
} else {
$page = new $pageClassOrArray($this);
$page->setTitle($title);
$this->addPage($page);
} else {
$pageClassOrArray->setTitle($title);
$this->addPage($pageClassOrArray);
}
}
}