diff --git a/README.md b/README.md index 67ab59f..46d295e 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ is the first step. ```php class SurveyForm extends MultiForm { - public static $start_step = 'SurveyFormPersonalDetailsStep'; + private static $start_step = 'SurveyFormPersonalDetailsStep'; } ``` @@ -141,7 +141,7 @@ the `$start_step` variable *SurveyForm*, but we call it `$next_steps`. ```php class SurveyFormPersonalDetailsStep extends MultiFormStep { - public static $next_steps = 'SurveyFormOrganisationDetailsStep'; + private static $next_steps = 'SurveyFormOrganisationDetailsStep'; public function getFields() { return new FieldList( @@ -167,7 +167,7 @@ SurveyFormOrganisationDetailsStep, then we can do something like this: ```php class SurveyFormOrganisationDetailsStep extends MultiFormStep { - public static $is_final_step = true; + private static $is_final_step = true; } ``` @@ -334,7 +334,7 @@ Here is an example of how to populate the email address from step 1 in step2 : ```php class Step1 extends MultiFormStep { - public static $next_steps = 'Step2'; + private static $next_steps = 'Step2'; public function getFields() { return new FieldList( @@ -345,7 +345,7 @@ class Step1 extends MultiFormStep class Step2 extends MultiFormStep { - public static $next_steps = 'Step3'; + private static $next_steps = 'Step3'; public function getFields() { $fields = new FieldList( @@ -378,7 +378,7 @@ Here is an example of what we could do here: ```php class SurveyForm extends MultiForm { - public static $start_step = 'SurveyFormPersonalDetailsStep'; + private static $start_step = 'SurveyFormPersonalDetailsStep'; public function finish($data, $form) { parent::finish($data, $form); @@ -557,7 +557,7 @@ For example: ```php class SurveyForm extends MultiForm { - public static $start_step = 'SurveyFormPersonalDetailsStep'; + private static $start_step = 'SurveyFormPersonalDetailsStep'; public function finish($data, $form) { parent::finish($data, $form); diff --git a/src/Models/MultiForm.php b/src/Models/MultiForm.php index 7a7f44b..2d9a81c 100644 --- a/src/Models/MultiForm.php +++ b/src/Models/MultiForm.php @@ -53,7 +53,7 @@ abstract class MultiForm extends Form * * @var string Classname of a {@link MultiFormStep} subclass */ - public static $start_step; + private static $start_step; /** * Set the casting for these fields. @@ -78,7 +78,7 @@ abstract class MultiForm extends Form * * @var array */ - public static $ignored_fields = [ + private static $ignored_fields = [ 'url', 'executeForm', 'SecurityID' @@ -94,7 +94,7 @@ abstract class MultiForm extends Form * * @var array */ - public static $actions_exempt_from_validation = [ + private static $actions_exempt_from_validation = [ 'action_prev' ]; @@ -146,7 +146,7 @@ abstract class MultiForm extends Form $validator = null; $applyValidation = true; - $actionNames = static::$actions_exempt_from_validation; + $actionNames = $this->config()->get('actions_exempt_from_validation'); if ($actionNames) { foreach ($actionNames as $exemptAction) { @@ -181,7 +181,7 @@ abstract class MultiForm extends Form // Disable security token - we tie a form to a session ID instead $this->disableSecurityToken(); - self::$ignored_fields[] = $getVar; + $this->config()->merge('ignored_fields', $getVar); } /** @@ -216,7 +216,7 @@ abstract class MultiForm extends Form */ public function getCurrentStep() { - $startStepClass = static::$start_step; + $startStepClass = $this->config()->get('start_step'); // Check if there was a start step defined on the subclass of MultiForm if (!isset($startStepClass)) { @@ -584,7 +584,7 @@ abstract class MultiForm extends Form $currentStep = $this->getCurrentStep(); if (is_array($data)) { foreach ($data as $field => $value) { - if (in_array($field, static::$ignored_fields)) { + if (in_array($field, $this->config()->get('ignored_fields'))) { unset($data[$field]); } } @@ -647,7 +647,7 @@ abstract class MultiForm extends Form { $stepsFound = ArrayList::create(); - $firstStep = DataObject::get_one(static::$start_step, "\"SessionID\" = {$this->session->ID}"); + $firstStep = DataObject::get_one($this->config()->get('start_step'), "\"SessionID\" = {$this->session->ID}"); $firstStep->LinkingMode = ($firstStep->ID == $this->getCurrentStep()->ID) ? 'current' : 'link'; $firstStep->setForm($this); $stepsFound->push($firstStep); diff --git a/src/Models/MultiFormStep.php b/src/Models/MultiFormStep.php index ac52501..5962e20 100644 --- a/src/Models/MultiFormStep.php +++ b/src/Models/MultiFormStep.php @@ -40,7 +40,7 @@ class MultiFormStep extends DataObject * * @var array|string */ - public static $next_steps; + private static $next_steps; /** * Each {@link MultiForm} subclass needs at least @@ -50,7 +50,7 @@ class MultiFormStep extends DataObject * * @var boolean */ - public static $is_final_step = false; + private static $is_final_step = false; /** * This variable determines whether a user can use @@ -243,7 +243,7 @@ class MultiFormStep extends DataObject */ public function getNextStep() { - $nextSteps = static::$next_steps; + $nextSteps = $this->config()->get('next_steps'); // Check if next_steps have been implemented properly if not the final step if (!$this->isFinalStep()) { @@ -277,7 +277,7 @@ class MultiFormStep extends DataObject public function getNextStepFromDatabase() { if ($this->SessionID && is_numeric($this->SessionID)) { - $nextSteps = static::$next_steps; + $nextSteps = $this->config()->get('next_steps'); if (is_string($nextSteps)) { return DataObject::get_one($nextSteps, "\"SessionID\" = {$this->SessionID}"); @@ -296,7 +296,7 @@ class MultiFormStep extends DataObject */ public function getNextSteps() { - return static::$next_steps; + return $this->config()->get('next_steps'); } /** @@ -394,7 +394,7 @@ class MultiFormStep extends DataObject */ public function canGoBack() { - return static::$can_go_back; + return $this->config()->get('can_go_back'); } /** @@ -405,7 +405,7 @@ class MultiFormStep extends DataObject */ public function isFinalStep() { - return static::$is_final_step; + return $this->config()->get('is_final_step'); } /** diff --git a/src/tasks/MultiFormPurgeTask.php b/src/tasks/MultiFormPurgeTask.php index cdcb49a..2765a05 100644 --- a/src/tasks/MultiFormPurgeTask.php +++ b/src/tasks/MultiFormPurgeTask.php @@ -27,7 +27,7 @@ class MultiFormPurgeTask extends BuildTask * * @var int */ - public static $session_expiry_days = 7; + private static $session_expiry_days = 7; /** * Run this cron task. @@ -46,7 +46,7 @@ class MultiFormPurgeTask extends BuildTask $delCount++; } } - echo $delCount . ' session records deleted that were older than ' . self::$session_expiry_days . ' days.'; + echo $delCount . ' session records deleted that were older than ' . $this->config()->get('session_expiry_days') . ' days.'; } /** @@ -59,7 +59,7 @@ class MultiFormPurgeTask extends BuildTask { return DataObject::get( MultiFormSession::class, - "DATEDIFF(NOW(), \"MultiFormSession\".\"Created\") > " . self::$session_expiry_days + "DATEDIFF(NOW(), \"MultiFormSession\".\"Created\") > " . $this->config()->get('session_expiry_days') ); } } diff --git a/tests/MultiFormObjectDecoratorTest.php b/tests/MultiFormObjectDecoratorTest.php index f0da517..bbcbc28 100644 --- a/tests/MultiFormObjectDecoratorTest.php +++ b/tests/MultiFormObjectDecoratorTest.php @@ -34,7 +34,6 @@ class MultiFormObjectDecoratorTest extends SapphireTest ->filter(['MultiFormIsTemporary' => 1]) ->map('Name') ->toArray(); - $this->assertNotContains('Test 1', $records); $this->assertNotContains('Test 2', $records); $this->assertContains('Test 3', $records); diff --git a/tests/MultiFormTest.php b/tests/MultiFormTest.php index d0e9169..50b2476 100644 --- a/tests/MultiFormTest.php +++ b/tests/MultiFormTest.php @@ -30,7 +30,7 @@ use SilverStripe\MultiForm\Models\MultiFormSession; */ class MultiFormTest extends FunctionalTest { - public static $fixture_file = 'MultiFormTest.yml'; + protected static $fixture_file = 'MultiFormTest.yml'; /** * @var MultiFormTestController @@ -120,7 +120,11 @@ class MultiFormTest extends FunctionalTest Config::modify()->set(MultiForm::class, 'get_var', 'SuperSessionID'); $form = $this->controller->Form(); - $this->assertContains('SuperSessionID', $form::$ignored_fields, "GET var wasn't added to ignored fields"); + $this->assertContains( + 'SuperSessionID', + $form->config()->get('ignored_fields'), + 'GET var wasn\'t added to ignored fields' + ); $this->assertContains( 'SuperSessionID', $form->FormAction(), diff --git a/tests/Stubs/MultiFormStepOne.php b/tests/Stubs/MultiFormStepOne.php index fdc87b8..1511ce1 100644 --- a/tests/Stubs/MultiFormStepOne.php +++ b/tests/Stubs/MultiFormStepOne.php @@ -14,7 +14,7 @@ use SilverStripe\MultiForm\Models\MultiFormStep; */ class MultiFormTestStepOne extends MultiFormStep implements TestOnly { - public static $next_steps = MultiFormTestStepTwo::class; + private static $next_steps = MultiFormTestStepTwo::class; public function getFields() { diff --git a/tests/Stubs/MultiFormTestForm.php b/tests/Stubs/MultiFormTestForm.php index aeb5ab5..ca569e2 100644 --- a/tests/Stubs/MultiFormTestForm.php +++ b/tests/Stubs/MultiFormTestForm.php @@ -11,10 +11,10 @@ use SilverStripe\MultiForm\Models\MultiForm; */ class MultiFormTestForm extends MultiForm implements TestOnly { - public static $start_step = MultiFormTestStepOne::class; + private static $start_step = MultiFormTestStepOne::class; public function getStartStep() { - return self::$start_step; + return $this->config()->get('start_step'); } } diff --git a/tests/Stubs/MultiFormTestStepThree.php b/tests/Stubs/MultiFormTestStepThree.php index a677c14..1644456 100644 --- a/tests/Stubs/MultiFormTestStepThree.php +++ b/tests/Stubs/MultiFormTestStepThree.php @@ -13,7 +13,7 @@ use SilverStripe\MultiForm\Models\MultiFormStep; */ class MultiFormTestStepThree extends MultiFormStep implements TestOnly { - public static $is_final_step = true; + private static $is_final_step = true; public function getFields() { diff --git a/tests/Stubs/MultiFormTestStepTwo.php b/tests/Stubs/MultiFormTestStepTwo.php index 2ad20d5..e1abf6a 100644 --- a/tests/Stubs/MultiFormTestStepTwo.php +++ b/tests/Stubs/MultiFormTestStepTwo.php @@ -12,7 +12,7 @@ use SilverStripe\MultiForm\Models\MultiFormStep; */ class MultiFormTestStepTwo extends MultiFormStep implements TestOnly { - public static $next_steps = MultiFormTestStepThree::class; + private static $next_steps = MultiFormTestStepThree::class; public function getFields() {