LeftAndMainFormRequestHandler::Link()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php
2
3
namespace LeKoala\Admini;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Forms\Form;
7
use SilverStripe\Forms\FormRequestHandler;
8
9
/**
10
 * Allows CMS forms to be decorated with additional context arguments.
11
 * By injecting additional IDs into the form link, LeftAndMain subclasses
12
 * can avoid relying on session state to record current page ID.
13
 * {@see CMSMain} for example usage.
14
 */
15
class LeftAndMainFormRequestHandler extends FormRequestHandler
16
{
17
    /**
18
     * Extra form identifiers (e.g. ID, OtherID)
19
     * @var array
20
     */
21
    protected $extra = [];
22
23
    public function __construct(Form $form, $extra = [])
24
    {
25
        parent::__construct($form);
26
        $this->extra = $extra;
27
    }
28
29
    public function Link($action = null)
30
    {
31
        // Add on extra urlsegments to end of link
32
        $parts = $this->extra;
33
        if ($action) {
34
            $parts[] = $action;
35
        }
36
        return parent::Link(Controller::join_links($parts));
37
    }
38
}
39