Completed
Push — master ( 663a06...123975 )
by Robbie
02:38
created

ElementFormController::Link()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 3
nop 1
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace DNADesign\ElementalUserForms\Control;
4
5
use DNADesign\Elemental\Controllers\ElementController;
6
use SilverStripe\Control\Controller;
7
use SilverStripe\UserForms\Control\UserDefinedFormController;
8
9
/**
10
 * Handles Form Submissions
11
 */
12
class ElementFormController extends ElementController
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17
    public function __construct($element = null)
18
    {
19
        parent::__construct($element);
20
21
        $current = Controller::curr();
22
23
        if ($current->getRequest()->isPOST()) {
24
            // handle the post request.
25
            $user = UserDefinedFormController::create($element);
26
            $form = $user->Form();
27
28
            $user->process($current->getRequest()->postVars(), $form);
29
        }
30
    }
31
32
    /**
33
     * @param string $action
34
     *
35
     * @return string
36
     */
37
    public function Link($action = null)
38
    {
39
        $id = $this->element->ID;
40
        $segment = Controller::join_links('element', $id, $action);
41
        $page = Director::get_current_page();
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalUserForms\Control\Director was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
43
        if ($page && !($page instanceof ElementController)) {
44
            return $page->Link($segment);
45
        }
46
47
        if ($controller = $this->getParentController()) {
0 ignored issues
show
Bug introduced by
The method getParentController() does not exist on DNADesign\ElementalUserF...l\ElementFormController. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
        if ($controller = $this->/** @scrutinizer ignore-call */ getParentController()) {
Loading history...
48
            return $controller->Link($segment);
49
        }
50
51
        return $segment;
52
    }
53
}
54