Skip to content

Commit

Permalink
API Move form factory handling into EditFormFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Sep 6, 2018
1 parent 8c2c542 commit 2cdff98
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
14 changes: 3 additions & 11 deletions src/Controllers/ElementalAreaController.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace DNADesign\Elemental\Controllers;

use DNADesign\Elemental\Forms\EditFormFactory;
use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\HTTPResponse_Exception;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

/**
* Controller for "ElementalArea" - handles loading and saving of in-line edit forms in an elemental area in admin
Expand Down Expand Up @@ -59,7 +59,7 @@ public function elementForm(HTTPRequest $request = null)
*/
public function getElementForm($elementID)
{
$scaffolder = Injector::inst()->get(DefaultFormFactory::class);
$scaffolder = Injector::inst()->get(EditFormFactory::class);
$element = BaseElement::get()->byID($elementID);

if (!$element) {
Expand All @@ -73,14 +73,6 @@ public function getElementForm($elementID)
['Record' => $element]
);

$form->addExtraClass('form--no-dividers');

/** @var HTMLEditorField $contentField */
$contentField = $form->Fields()->fieldByName('Root.Main.HTML');
if ($contentField) {
$contentField->setRows(5);
}

return $form;
}
}
34 changes: 34 additions & 0 deletions src/Forms/EditFormFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace DNADesign\Elemental\Forms;

use SilverStripe\Control\RequestHandler;
use SilverStripe\Forms\DefaultFormFactory;
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;

class EditFormFactory extends DefaultFormFactory
{
public function getForm(RequestHandler $controller = null, $name = self::DEFAULT_NAME, $context = [])
{
$form = parent::getForm($controller, $name, $context);

// Remove divider lines between form fields
$form->addExtraClass('form--no-dividers');

return $form;
}

protected function getFormFields(RequestHandler $controller = null, $name, $context = [])
{
$fields = parent::getFormFields($controller, $name, $context);

/** @var HTMLEditorField $contentField */
$contentField = $fields->fieldByName('Root.Main.HTML');
if ($contentField) {
$contentField->setRows(5);
}

return $fields;
}
}

0 comments on commit 2cdff98

Please sign in to comment.