Completed
Pull Request — master (#12)
by Matthew
11:11
created

ManageableDataObjectForm::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 3
1
<?php
2
3
namespace Dynamic\ManageableDataObject\Form;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Core\Injector\Injector;
7
use SilverStripe\Forms\Form;
8
use SilverStripe\Forms\FormAction;
9
10
/**
11
 * Class ManageableDataObjectForm
12
 */
13
class ManageableDataObjectForm extends Form
14
{
15
16
    /**
17
     * ManageableDataObjectForm constructor.
18
     *
19
     * @param Controller $controller
20
     * @param string $name
21
     * @param \SilverStripe\ORM\DataObject|string $object
22
     */
23
    public function __construct(Controller $controller, $name, $object)
24
    {
25
        if (is_string($object) && class_exists($object)) {
26
            $object = Injector::inst()->get($object);
27
        }
28
29
		/** @var \SilverStripe\ORM\DataObject|\Dynamic\ManageableDataObject\Interfaces\ManageableDataObjectInterface $object */
30
        $fields = $object->getFrontEndFields();
31
        $actions = $object->getFrontEndActions();
32
        if (!$actions->dataFieldByName('action_doSaveObject')) {
33
            $actions->push(FormAction::create('doSaveObject')->setTitle('Save'));
34
        }
35
        $validator = $object->getFrontEndRequiredFields();
36
37
        parent::__construct($controller, $name, $fields, $actions, $validator);
38
    }
39
40
}
41