Skip to content

Commit

Permalink
Merge pull request #70 from creative-commoners/pulls/2.0/upgrade-ss4
Browse files Browse the repository at this point in the history
Review SS4 update
  • Loading branch information
robbieaverill authored Jan 10, 2018
2 parents 17a554f + d52ba7d commit 231f195
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 36 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
/codecov.yml export-ignore
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ matrix:
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
- php: 7.2
env: DB=MYSQL PHPUNIT_TEST=1

before_script:
# Init PHP
Expand Down
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# MultiForm Module

[![Build Status](https://travis-ci.org/silverstripe/silverstripe-multiform.svg?branch=master)](https://travis-ci.org/silverstripe/silverstripe-multiform)
[![Latest Stable Version](https://poser.pugx.org/silverstripe/multiform/version.svg)](https://github.com/silverstripe/silverstripe-multiform/releases)
[![Latest Unstable Version](https://poser.pugx.org/silverstripe/multiform/v/unstable.svg)](https://packagist.org/packages/silverstripe/multiform)
[![Total Downloads](https://poser.pugx.org/silverstripe/multiform/downloads.svg)](https://packagist.org/packages/silverstripe/multiform)
[![License](https://poser.pugx.org/silverstripe/multiform/license.svg)](https://github.com/silverstripe/silverstripe-multiform/blob/master/license.md)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/silverstripe/silverstripe-multiform.svg)](https://scrutinizer-ci.com/g/silverstripe/silverstripe-multiform/?branch=master)
[![Code Coverage](https://img.shields.io/codecov/c/github/silverstripe/silverstripe-multiform.svg)](https://codecov.io/gh/silverstripe/silverstripe-multiform)

## Introduction

Expand All @@ -22,10 +20,11 @@ individual implementation can be customized to the project requirements.

## Requirements

SilverStripe 4.0+. For SilverStripe 3 support please use `1.3` or below.
* SilverStripe ^4.0

## What it does do
**Note:** For a SilverStripe 3.x compatible version, please use [the 1.x release line](https://github.com/silverstripe/silverstripe-multiform/tree/1.3).

## What it does do

* Abstracts fields, actions and validation to each individual step.
* Maintains flow control automatically, so it knows which steps are ahead and
Expand Down Expand Up @@ -84,7 +83,7 @@ SilverStripe site using this command (while in the directory where your site is
currently located)

```
composer require "silverstripe/multiform:*"
composer require silverstripe/multiform
```

### 2. Create subclass of MultiForm
Expand All @@ -96,7 +95,8 @@ For the above example, our multi-form will be called *SurveyForm*
```php
use SilverStripe\MultiForm\Forms\MultiForm;

class SurveyForm extends MultiForm {
class SurveyForm extends MultiForm
{

}
```
Expand Down Expand Up @@ -173,15 +173,16 @@ Keep in mind that our multi-form also requires an end point. This step is the
final one, and needs to have another variable set to let the multi-form system know
this is the final step.

So, if we assume that the last step in our process is
SurveyFormOrganisationDetailsStep, then we can do something like this:
So, if we assume that the last step in our process is OrganisationDetailsStep, then we can do something like this:

```php
use SilverStripe\MultiForm\Models\MultiFormStep;

class OrganisationDetailsStep extends MultiFormStep
{
private static $is_final_step = true;

...
}
```

Expand Down Expand Up @@ -328,10 +329,10 @@ template.

### 7. Loading values from other steps

There are several use cases were you want to pre-populate a value based
based on the submission value of another step. There are two methods supporting this:
There are several use cases where you want to pre-populate a value based on the submission value of another step.
There are two methods supporting this:

* `getValueFromOtherStep()` load any submitted value from another step from the session
* `getValueFromOtherStep()` loads any submitted value from another step from the session
* `copyValueFromOtherStep()` saves you the repeated work of adding the same lines of code again and again.

Here is an example of how to populate the email address from step 1 in step2 :
Expand Down Expand Up @@ -410,26 +411,26 @@ class SurveyForm extends MultiForm
"SessionID = {$this->session->ID}"
);

if($steps) {
foreach($steps as $step) {
if ($steps) {
foreach ($steps as $step) {
if($step->class == PersonalDetailsStep::class) {
$member = Member::create();
$data = $step->loadData();

if($data) {
if ($data) {
$member->update($data);
$member->write();
}
}

if($step->class == OrganisationDetailsStep::class) {
if ($step->class == OrganisationDetailsStep::class) {
$organisation = Organisation::create();
$data = $step->loadData();

if($data) {
if ($data) {
$organisation->update($data);

if($member && $member->ID) {
if ($member && $member->ID) {
$organisation->MemberID = $member->ID;
}

Expand Down Expand Up @@ -460,9 +461,9 @@ use SilverStripe\ORM\DataObject;

class Organisation extends DataObject
{
private static $db = array(
private static $db = [
// Add your Organisation fields here
);
];
}
```
#### Warning
Expand Down Expand Up @@ -530,7 +531,7 @@ class MyStep extends MultiFormStep
public function getNextStep()
{
$data = $this->loadData();
if($data['Gender'] == 'Male') {
if(isset($data['Gender']) && $data['Gender'] == 'Male') {
return TestThirdCase1Step::class;
} else {
return TestThirdCase2Step::class;
Expand Down Expand Up @@ -594,7 +595,7 @@ class SurveyForm extends MultiForm
$steps = MultiFormStep::get()->filter(['SessionID' => $this->session->ID]);

if($steps) {
foreach($steps as $step) {
foreach ($steps as $step) {
// Shows the step data (unserialized by loadData)
Debug::show($step->loadData());
}
Expand Down Expand Up @@ -632,7 +633,7 @@ after their creation.

You can run the task from the URL, by using http://mysite.com/dev/tasks/MultiFormPurgeTask?flush=1

MultiFormPurgeTask is a subclass of *BuildTask*, so can be , so can be run using the [SilverStripe CLI tools](http://doc.silverstripe.org/framework/en/topics/commandline).
MultiFormPurgeTask is a subclass of *BuildTask*, so can be run using the [SilverStripe CLI tools](http://doc.silverstripe.org/framework/en/topics/commandline).

One way of automatically running this on a UNIX based machine is by cron.

Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "silverstripe/multiform",
"description": "SilverStripe forms with multiple steps, flow control and state persistence",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": [
"silverstripe",
"forms"
],
"license": "BSD-3-Clause",
"authors": [
{
"name": "Ingo Schommer",
Expand All @@ -17,12 +18,12 @@
}
],
"require": {
"silverstripe/framework": "^4@dev"
"silverstripe/framework": "^4"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"squizlabs/php_codesniffer": "^3.0",
"silverstripe/versioned": "^1@dev"
"silverstripe/versioned": "^1"
},
"extra": {
"branch-alias": {
Expand All @@ -35,7 +36,6 @@
"SilverStripe\\MultiForm\\Tests\\": "tests/"
}
},
"license": "BSD-3-Clause",
"minimum-stability": "dev",
"prefer-stable": true
}
19 changes: 13 additions & 6 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
en:
SilverStripe\MultiForm\MultiForm:
BACK: Back
NEXT: Next
SUBMIT: Submit
SilverStripe\MultiForm\MultiFormSession:
SilverStripe\MultiForm\Models\MultiFormSession:
PLURALNAME: 'Multi Form Sessions'
PLURALS:
one: 'A Multi Form Session'
other: '{count} Multi Form Sessions'
SINGULARNAME: 'Multi Form Session'
SilverStripe\MultiForm\MultiFormStep:
SilverStripe\MultiForm\Models\MultiFormStep:
BACK: Back
NEXT: Next
PLURALNAME: 'Multi Form Steps'
PLURALS:
one: 'A Multi Form Step'
other: '{count} Multi Form Steps'
SINGULARNAME: 'Multi Form Step'
SUBMIT: Submit
SilverStripe\MultiForm\MultiForm:
ProgressPercent: 'You''ve completed {percent}% ({completedSteps}/{totalSteps})'
2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017, SilverStripe Limited
Copyright (c) 2018, SilverStripe Limited
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
9 changes: 9 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
</rule>
</ruleset>
2 changes: 1 addition & 1 deletion src/Forms/MultiForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* you have to allow the following methods:
*
* <code>
* private static $allowed_actions = array('next','prev');
* private static $allowed_actions = ['next','prev'];
* </code>
*
*/
Expand Down

0 comments on commit 231f195

Please sign in to comment.