mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
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)
This commit is contained in:
parent
abb032b6f7
commit
24b768ecfe
@ -544,20 +544,15 @@ abstract class MultiForm extends Form {
|
|||||||
* first step. We run {@link getAllStepsRecursive} passing the steps found
|
* first step. We run {@link getAllStepsRecursive} passing the steps found
|
||||||
* by reference to get a listing of the steps.
|
* by reference to get a listing of the steps.
|
||||||
*
|
*
|
||||||
* @return DataObjectSet
|
* @return DataObjectSet of MultiFormStep instances
|
||||||
*/
|
*/
|
||||||
public function getAllStepsLinear() {
|
public function getAllStepsLinear() {
|
||||||
$stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet();
|
$stepsFound = (class_exists('ArrayList')) ? new ArrayList() : new DataObjectSet();
|
||||||
|
|
||||||
$firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}");
|
$firstStep = DataObject::get_one($this->stat('start_step'), "\"SessionID\" = {$this->session->ID}");
|
||||||
$templateData = array(
|
$firstStep->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link';
|
||||||
'ID' => $firstStep->ID,
|
$firstStep->setForm($this);
|
||||||
'ClassName' => $firstStep->class,
|
$stepsFound->push($firstStep);
|
||||||
'Title' => $firstStep->title ? $firstStep->title : $firstStep->class,
|
|
||||||
'SessionID' => $this->session->Hash,
|
|
||||||
'LinkingMode' => ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link'
|
|
||||||
);
|
|
||||||
$stepsFound->push(new ArrayData($templateData));
|
|
||||||
|
|
||||||
$this->getAllStepsRecursive($firstStep, $stepsFound);
|
$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 $step Subclass of MultiFormStep to find the next step of
|
||||||
* @param $stepsFound $stepsFound DataObjectSet reference, the steps found to call back on
|
* @param $stepsFound $stepsFound DataObjectSet reference, the steps found to call back on
|
||||||
* @return DataObjectSet
|
* @return DataObjectSet of MultiFormStep instances
|
||||||
*/
|
*/
|
||||||
protected function getAllStepsRecursive($step, &$stepsFound) {
|
protected function getAllStepsRecursive($step, &$stepsFound) {
|
||||||
// Find the next step to the current step, the final step has no next step
|
// Find the next step to the current step, the final step has no next step
|
||||||
if(!$step->isFinalStep()) {
|
if(!$step->isFinalStep()) {
|
||||||
if($step->getNextStep()) {
|
if($step->getNextStep()) {
|
||||||
// Is this step in the DB? If it is, we use that
|
// Is this step in the DB? If it is, we use that
|
||||||
if($nextStep = $step->getNextStepFromDatabase()) {
|
$nextStep = $step->getNextStepFromDatabase();
|
||||||
$record = array(
|
if(!$nextStep) {
|
||||||
'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 {
|
|
||||||
// If it's not in the DB, we use a singleton instance of it instead - this step hasn't been accessed yet
|
// 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());
|
$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
|
// Add the array data, and do a callback
|
||||||
$stepsFound->push(new ArrayData($record));
|
$stepsFound->push($nextStep);
|
||||||
$this->getAllStepsRecursive($nextStep, $stepsFound);
|
$this->getAllStepsRecursive($nextStep, $stepsFound);
|
||||||
}
|
}
|
||||||
// Once we've reached the final step, we just return what we've collected
|
// Once we've reached the final step, we just return what we've collected
|
||||||
|
@ -114,7 +114,7 @@ class MultiFormStep extends DataObject {
|
|||||||
* @return string Title of this step
|
* @return string Title of this step
|
||||||
*/
|
*/
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
return $this->title;
|
return $this->title ? $this->title : $this->class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user