From 24b768ecfeb126b7fedc5bf86248be380ff54994 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 12 Jul 2011 11:40:03 +0200 Subject: [PATCH] BUGFIX Using actual step instances instead of half-complete ArrayData templates in MultiForm->getAllStepsLinear()/getAllStepsRecursive(). Linking current form instance on these steps, and ensuring the title has a fallback to classname globally (not just when retrieving steps through getAllSteps*() methods) --- code/MultiForm.php | 36 +++++++++++------------------------- code/MultiFormStep.php | 2 +- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/code/MultiForm.php b/code/MultiForm.php index 32b985b..df7ba11 100644 --- a/code/MultiForm.php +++ b/code/MultiForm.php @@ -544,20 +544,15 @@ abstract class MultiForm extends Form { * first step. We run {@link getAllStepsRecursive} passing the steps found * by reference to get a listing of the steps. * - * @return DataObjectSet + * @return DataObjectSet of MultiFormStep instances */ public function getAllStepsLinear() { $stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet(); $firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}"); - $templateData = array( - 'ID' => $firstStep->ID, - 'ClassName' => $firstStep->class, - 'Title' => $firstStep->title ? $firstStep->title : $firstStep->class, - 'SessionID' => $this->session->Hash, - 'LinkingMode' => ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link' - ); - $stepsFound->push(new ArrayData($templateData)); + $firstStep->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link'; + $firstStep->setForm($this); + $stepsFound->push($firstStep); $this->getAllStepsRecursive($firstStep, $stepsFound); @@ -574,31 +569,22 @@ abstract class MultiForm extends Form { * * @param $step Subclass of MultiFormStep to find the next step of * @param $stepsFound $stepsFound DataObjectSet reference, the steps found to call back on - * @return DataObjectSet + * @return DataObjectSet of MultiFormStep instances */ protected function getAllStepsRecursive($step, &$stepsFound) { // Find the next step to the current step, the final step has no next step if(!$step->isFinalStep()) { if($step->getNextStep()) { // Is this step in the DB? If it is, we use that - if($nextStep = $step->getNextStepFromDatabase()) { - $record = array( - 'ID' => $nextStep->ID, - 'ClassName' => $nextStep->class, - 'Title' => $nextStep->title ? $nextStep->title : $nextStep->class, - 'SessionID' => $this->session->Hash, - 'LinkingMode' => ($nextStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link' - ); - } else { + $nextStep = $step->getNextStepFromDatabase(); + if(!$nextStep) { // If it's not in the DB, we use a singleton instance of it instead - this step hasn't been accessed yet $nextStep = singleton($step->getNextStep()); - $record = array( - 'ClassName' => $nextStep->class, - 'Title' => $nextStep->title ? $nextStep->title : $nextStep->class - ); - } + } + $nextStep->LinkingMode = ($nextStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link'; + $nextStep->setForm($this); // Add the array data, and do a callback - $stepsFound->push(new ArrayData($record)); + $stepsFound->push($nextStep); $this->getAllStepsRecursive($nextStep, $stepsFound); } // Once we've reached the final step, we just return what we've collected diff --git a/code/MultiFormStep.php b/code/MultiFormStep.php index dfc11e2..0c0cef9 100644 --- a/code/MultiFormStep.php +++ b/code/MultiFormStep.php @@ -114,7 +114,7 @@ class MultiFormStep extends DataObject { * @return string Title of this step */ public function getTitle() { - return $this->title; + return $this->title ? $this->title : $this->class; } /**