Skip to content

Commit

Permalink
Modify ElementForm to contain its’ own form builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilr committed Oct 9, 2017
1 parent 07307bb commit 54b18f2
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 38 deletions.
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.
25 changes: 25 additions & 0 deletions src/Control/ElementFormController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace DNADesign\Elemental\UserForms\Control;

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

class ElementFormController extends ElementController
{
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);
}
}
}
55 changes: 55 additions & 0 deletions src/Model/ElementForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace DNADesign\Elemental\UserForms\Model;

use SilverStripe\UserForms\Control\UserDefinedFormController;
use SilverStripe\UserForms\UserForm;
use SilverStripe\Control\Controller;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\UserForms\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 = 'elemental-userforms/images/form.svg';

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

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/Elemental/UserForms/Model/ElementForm.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div class="elementform-form">
$ElementForm
</div>

0 comments on commit 54b18f2

Please sign in to comment.