diff --git a/src/Models/MultiForm.php b/src/Models/MultiForm.php index 5882d25..0c8e158 100644 --- a/src/Models/MultiForm.php +++ b/src/Models/MultiForm.php @@ -180,7 +180,7 @@ abstract class MultiForm extends Form // Disable security token - we tie a form to a session ID instead $this->disableSecurityToken(); - $this->config()->merge('ignored_fields', $getVar); + $this->config()->merge('ignored_fields', [$getVar]); } /** @@ -220,7 +220,7 @@ abstract class MultiForm extends Form // Check if there was a start step defined on the subclass of MultiForm if (!isset($startStepClass)) { user_error( - 'MultiForm::init(): Please define a $start_step on ' . $this->class, + 'MultiForm::init(): Please define a $start_step on ' . static::class, E_USER_ERROR ); } @@ -302,13 +302,9 @@ abstract class MultiForm extends Form // If there was no session found, create a new one instead if (!$this->session) { - $this->session = MultiFormSession::create(); - } - - // Create encrypted identification to the session instance if it doesn't exist - if (!$this->session->Hash) { - $this->session->Hash = sha1($this->session->ID . '-' . microtime()); - $this->session->write(); + $session = MultiFormSession::create(); + $session->write(); + $this->session = $session; } } @@ -433,30 +429,6 @@ abstract class MultiForm extends Form return $actions; } - /** - * Return a rendered version of this form, with a specific template. - * Looks through the step ancestory templates (MultiFormStep, current step - * subclass template) to see if one is available to render the form with. If - * any of those don't exist, look for a default Form template to render - * with instead. - * - * @return SSViewer object to render the template with - */ - public function forTemplate() - { - $return = $this->renderWith([ - $this->getCurrentStep()->class, - 'MultiFormStep', - $this->class, - 'MultiForm', - 'Form' - ]); - - $this->clearMessage(); - - return $return; - } - /** * This method saves the data on the final step, after submitting. * It should always be overloaded with parent::finish($data, $form) diff --git a/src/Models/MultiFormSession.php b/src/Models/MultiFormSession.php index 7b92259..fa9b5cf 100644 --- a/src/Models/MultiFormSession.php +++ b/src/Models/MultiFormSession.php @@ -78,4 +78,14 @@ class MultiFormSession extends DataObject parent::onBeforeDelete(); } + + public function onAfterWrite() + { + parent::onAfterWrite(); + // Create encrypted identification to the session instance if it doesn't exist + if (!$this->Hash) { + $this->Hash = sha1($this->ID . '-' . microtime()); + $this->write(); + } + } } diff --git a/src/Models/MultiFormStep.php b/src/Models/MultiFormStep.php index 493b3a0..f02e54d 100644 --- a/src/Models/MultiFormStep.php +++ b/src/Models/MultiFormStep.php @@ -63,7 +63,7 @@ class MultiFormStep extends DataObject * * @var boolean */ - protected static $can_go_back = true; + private static $can_go_back = true; /** * Title of this step. @@ -249,7 +249,7 @@ class MultiFormStep extends DataObject if (!isset($nextSteps)) { user_error( 'MultiFormStep->getNextStep(): Please define at least one $next_steps on ' - . $this->class, + . static::class, E_USER_ERROR ); } @@ -314,8 +314,8 @@ class MultiFormStep extends DataObject $step->setForm($this->form); if ($step->getNextStep()) { - if ($step->getNextStep() == $this->class) { - return $step->class; + if ($step->getNextStep() == static::class) { + return get_class($step); } } } @@ -417,7 +417,7 @@ class MultiFormStep extends DataObject */ public function isCurrentStep() { - return ($this->class == $this->getSession()->CurrentStep()->class) ? true : false; + return (static::class == get_class($this->getSession()->CurrentStep())) ? true : false; } /** diff --git a/templates/Includes/MultiFormProgressList.ss b/templates/Includes/MultiFormProgressList.ss index af77977..a183150 100644 --- a/templates/Includes/MultiFormProgressList.ss +++ b/templates/Includes/MultiFormProgressList.ss @@ -4,7 +4,7 @@ <% if $LinkingMode = current %> <% else %> <% if $ID %> - + <% end_if %> <% end_if %> diff --git a/templates/Includes/MultiFormProgressPercent.ss b/templates/Includes/MultiFormProgressPercent.ss index d47b1de..705277e 100644 --- a/templates/Includes/MultiFormProgressPercent.ss +++ b/templates/Includes/MultiFormProgressPercent.ss @@ -1 +1 @@ -

<%t SilverStripe\\MultiForm\\MultiForm.ProgressPercent "You've completed {percent}% ({completedSteps}/{totalSteps})" percent=$CompletedPercent.Nice completedSteps=$CompletedStepCount totalSteps$TotalStepCount %>

+

<%t SilverStripe\\MultiForm\\MultiForm.ProgressPercent "You've completed {percent}% ({completedSteps}/{totalSteps})" percent=$CompletedPercent.Nice completedSteps=$CompletedStepCount totalSteps=$TotalStepCount %>

diff --git a/tests/MultiFormTest.php b/tests/MultiFormTest.php index d09d73e..8aff129 100644 --- a/tests/MultiFormTest.php +++ b/tests/MultiFormTest.php @@ -93,7 +93,7 @@ class MultiFormTest extends FunctionalTest public function testParentForm() { $currentStep = $this->form->getCurrentStep(); - $this->assertEquals($currentStep->getForm()->class, $this->form->class); + $this->assertEquals(get_class($currentStep->getForm()), get_class($this->form)); } public function testTotalStepCount()