Skip to content

Commit

Permalink
Merge pull request #1 from creative-commoners/pulls/CC-163-userform-o…
Browse files Browse the repository at this point in the history
…n-block

Allow editors to define userform on block
  • Loading branch information
wilr authored Oct 17, 2017
2 parents 6db07a8 + 8115cfe commit d64b1c4
Show file tree
Hide file tree
Showing 17 changed files with 381 additions and 44 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# For more information about the properties used in this file,
# please see the EditorConfig documentation:
# http://editorconfig.org

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[{*.yml,package.json}]
indent_size = 2

# The indent size used in the package.json file cannot be changed:
# https://github.com/npm/npm/pull/3180#issuecomment-16336516
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/tests export-ignore
/docs export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/.scrutinizer.yml export-ignore
12 changes: 12 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
inherit: true

tools:
external_code_coverage: false

checks:
php:
code_rating: true
duplication: true

filter:
paths: [src/*, tests/*]
37 changes: 37 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
language: php

dist: trusty

env:
global:
- COMPOSER_ROOT_VERSION=1.x-dev

matrix:
include:
- php: 5.6
env: DB=MYSQL PHPCS_TEST=1 PHPUNIT_TEST=1
- php: 7.0
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.0
env: DB=MYSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1

before_script:
# Init PHP
- phpenv rehash
- phpenv config-rm xdebug.ini

# Install composer dependencies
- composer validate
- composer require silverstripe/recipe-cms 1.0.x-dev --no-update
- if [[ $DB == PGSQL ]]; then composer require silverstripe/postgresql:2.0.x-dev --no-update; fi
- composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile

script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# silverstripe-elemental-userforms
Adds a new element for usersforms
# SilverStripe Elemental UserForms

[![Build Status](http://img.shields.io/travis/dnadesign/silverstripe-elemental-userforms.svg?style=flat-square)](https://travis-ci.org/dnadesign/silverstripe-elemental-userforms)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-userforms/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/dnadesign/silverstripe-elemental-userforms/?branch=master)
[![codecov](https://codecov.io/gh/dnadesign/silverstripe-elemental-userforms/branch/master/graph/badge.svg)](https://codecov.io/gh/dnadesign/silverstripe-elemental-userforms)
[![Version](http://img.shields.io/packagist/v/dnadesign/silverstripe-elemental-userforms.svg?style=flat-square)](https://packagist.org/packages/dnadesign/silverstripe-elemental-userforms)
[![License](http://img.shields.io/packagist/l/dnadesign/silverstripe-elemental-userforms.svg?style=flat-square)](LICENSE.md)

## Introduction

Adds a new form element for SilverStripe Elemental. This block allows users to
construct User Forms using the SilverStripe UserForms module.

## Installation

```
composer require "dnadesign/silverstripe-elemental-userforms"
```


1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
comment: false
21 changes: 17 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dnadesign/silverstripe-elemental-userforms",
"description": "Adds a new element for usersforms",
"type": "silverstripe-module",
"type": "silverstripe-vendormodule",
"keywords": ["silverstripe", "element", "elemental", "content blocks", "userforms"],
"license": "BSD-3-Clause",
"authors": [{
Expand All @@ -12,9 +12,22 @@
"prefer-stable": true,
"require": {
"dnadesign/silverstripe-elemental": "dev-ss4",
"silverstripe/userforms": "dev-master"
"silverstripe/userforms": "5.0.x-dev",
"silverstripe/vendor-plugin": "^1.0"
},
"extra": {
"installer-name": "elemental-userforms"
}
"installer-name": "elemental-userforms",
"branch-alias": {
"dev-master": "1.x-dev"
},
"expose": [
"images"
]
},
"autoload": {
"psr-4": {
"DNADesign\\ElementalUserForms\\": "src/",
"DNADesign\\ElementalUserForms\\Tests\\": "tests/php/"
}
}
}
25 changes: 25 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Contributing

Any open source product is only as good as the community behind it. You can participate by sharing code, ideas, or
simply helping others. No matter what your skill level is, every contribution counts.

See our [high level overview](http://silverstripe.org/contributing-to-silverstripe) on silverstripe.org on how you can
help out.

Or, for more detailed guidance, read one of the following pages:

* [Sharing your opinion and raising issues](http://docs.silverstripe.org/en/contributing/issues_and_bugs/)
* [Providing code, whether it's creating a feature or fixing a bug](http://docs.silverstripe.org/en/contributing/code/)
* [Writing and translating documentation](http://docs.silverstripe.org/en/contributing/translations/)
* [Translating user-interface elements](http://docs.silverstripe.org/en/contributing/translation_process/)

## Copyright

**IMPORTANT: By supplying code in patches, tickets and pull requests, you agree to assign copyright of that code to
DNA DESIGNED COMMUNICATIONS LIMITED, on the condition that DNA DESIGNED COMMUNICATIONS LIMITED releases that code under
the BSD license.** unless otherwise noted.

We ask for this so that the ownership in the license is clear and unambiguous, and so that community involvement doesn't
stop us from being able to continue supporting these projects. By releasing this code under a permissive license, this
copyright assignment won't prevent you from using the code in any way you see fit.

18 changes: 18 additions & 0 deletions images/form.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<phpunit bootstrap="vendor/silverstripe/framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>

<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
<exclude>
<directory suffix=".php">tests/php</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
53 changes: 53 additions & 0 deletions src/Control/ElementFormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace DNADesign\ElementalUserForms\Control;

use DNADesign\Elemental\Controllers\ElementController;
use SilverStripe\Control\Controller;
use SilverStripe\UserForms\Control\UserDefinedFormController;

/**
* Handles Form Submissions
*/
class ElementFormController extends ElementController
{
/**
* {@inheritDoc}
*/
public function __construct($element = null)
{
parent::__construct($element);

$current = Controller::curr();

if ($current->getRequest()->isPOST()) {
// handle the post request.
$user = UserDefinedFormController::create($element);
$form = $user->Form();

$user->process($current->getRequest()->postVars(), $form);
}
}

/**
* @param string $action
*
* @return string
*/
public function Link($action = null)
{
$id = $this->element->ID;
$segment = Controller::join_links('element', $id, $action);
$page = Director::get_current_page();

if ($page && !($page instanceof ElementController)) {
return $page->Link($segment);
}

if ($controller = $this->getParentController()) {
return $controller->Link($segment);
}

return $segment;
}
}
58 changes: 58 additions & 0 deletions src/Model/ElementForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace DNADesign\ElementalUserForms\Model;

use SilverStripe\UserForms\Control\UserDefinedFormController;
use SilverStripe\UserForms\UserForm;
use SilverStripe\Control\Controller;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\ElementalUserForms\Control\ElementFormController;

class ElementForm extends BaseElement
{
use UserForm;

/**
* @var string
*/
private static $table_name = 'ElementForm';

/**
* @var string
*/
private static $title = 'Form';

/**
* @var string
*/
private static $icon = 'dnadesign/silverstripe-elemental-userforms:images/form.svg';

/**
* @var string
*/
private static $controller_class = ElementFormController::class;

/**
* @return UserForm
*/
public function ElementForm()
{
$controller = new UserDefinedFormController($this);
$current = Controller::curr();

if ($current && $current->getAction() == 'finished') {
return $controller->renderWith('ReceivedFormSubmission');
}

$form = $controller->Form();
$form->setFormAction(
Controller::join_links(
$current->Link(),
'element',
$this->owner->ID
)
);

return $form;
}
}
38 changes: 0 additions & 38 deletions src/Model/ElementUserDefinedForm.php

This file was deleted.

3 changes: 3 additions & 0 deletions templates/DNADesign/ElementalUserForms/Model/ElementForm.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="formelement__form">
$ElementForm
</div>
Loading

0 comments on commit d64b1c4

Please sign in to comment.