parent
1f942acd38
commit
754f854dd0
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue