ManageableDataObjectForm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 25
rs 10
ccs 9
cts 9
cp 1
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 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