ENHANCEMENT Update README and add codesniffer rules

This commit is contained in:
Raissa North 2018-01-10 13:55:39 +13:00
parent 09bcc63874
commit 7532724eb7
8 changed files with 56 additions and 36 deletions

1
.gitattributes vendored
View File

@ -4,3 +4,4 @@
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
/.codecov.yml export-ignore

View File

@ -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

View File

@ -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
@ -22,11 +20,12 @@ 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
**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
behind. It also can retrieve an entire step process from start to finish, useful
@ -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
@ -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
{
}
```
@ -173,8 +173,7 @@ 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;
@ -182,6 +181,8 @@ use SilverStripe\MultiForm\Models\MultiFormStep;
class OrganisationDetailsStep extends MultiFormStep
{
private static $is_final_step = true;
...
}
```
@ -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 :
@ -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;
}
@ -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
@ -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;
@ -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());
}
@ -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.

View File

@ -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",
@ -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": {
@ -35,7 +36,6 @@
"SilverStripe\\MultiForm\\Tests\\": "tests/"
}
},
"license": "BSD-3-Clause",
"minimum-stability": "dev",
"prefer-stable": true
}

View File

@ -1,11 +1,18 @@
en:
SilverStripe\MultiForm\MultiForm:
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\Models\MultiFormStep:
BACK: Back
NEXT: Next
SUBMIT: Submit
SilverStripe\MultiForm\MultiFormSession:
PLURALNAME: 'Multi Form Sessions'
SINGULARNAME: 'Multi Form Session'
SilverStripe\MultiForm\MultiFormStep:
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})'

View File

@ -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:

9
phpcs.xml.dist Normal file
View File

@ -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>

View File

@ -25,7 +25,7 @@ use SilverStripe\ORM\DataObject;
* you have to allow the following methods:
*
* <code>
* private static $allowed_actions = array('next','prev');
* private static $allowed_actions = ['next','prev'];
* </code>
*
*/