ManageableDataObjectForm::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 15
rs 10
ccs 9
cts 9
cp 1
crap 4
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 4
    public function __construct(Controller $controller, $name, $object)
24
    {
25 4
        if (is_string($object) && class_exists($object)) {
26 4
            $object = Injector::inst()->get($object);
27
        }
28
29
		/** @var \SilverStripe\ORM\DataObject|\Dynamic\ManageableDataObject\Interfaces\ManageableDataObjectInterface $object */
30 4
        $fields = $object->getFrontEndFields();
31 4
        $actions = $object->getFrontEndActions();
32 4
        if (!$actions->dataFieldByName('action_doSaveObject')) {
33 4
            $actions->push(FormAction::create('doSaveObject')->setTitle('Save'));
34
        }
35 4
        $validator = $object->getFrontEndRequiredFields();
36
37 4
        parent::__construct($controller, $name, $fields, $actions, $validator);
38
    }
39
40
}
41