Completed
Push — master ( 0ebf95...33622c )
by Damian
12s
created

SubsitesTreeDropdownField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 43
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Field() 0 7 1
A setSubsiteID() 0 3 1
A tree() 0 8 1
A getSubsiteID() 0 3 1
1
<?php
2
3
namespace SilverStripe\Subsites\Forms;
4
5
use SilverStripe\Control\Controller;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Forms\TreeDropdownField;
8
use SilverStripe\View\Requirements;
9
use SilverStripe\Subsites\State\SubsiteState;
10
11
/**
12
 * Wraps around a TreedropdownField to add ability for temporary
13
 * switching of subsite sessions.
14
 *
15
 * @package subsites
16
 */
17
class SubsitesTreeDropdownField extends TreeDropdownField
18
{
19
    private static $allowed_actions = [
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
20
        'tree'
21
    ];
22
23
    protected $subsiteID = 0;
24
25
    /**
26
     * Extra HTML classes
27
     *
28
     * @skipUpgrade
29
     * @var string[]
30
     */
31
    protected $extraClasses = ['SubsitesTreeDropdownField'];
32
33
    public function Field($properties = [])
34
    {
35
        $html = parent::Field($properties);
36
37
        Requirements::javascript('silverstripe/subsitesjavascript/SubsitesTreeDropdownField.js');
38
39
        return $html;
40
    }
41
42
    public function setSubsiteID($id)
43
    {
44
        $this->subsiteID = $id;
45
    }
46
47
    public function getSubsiteID()
48
    {
49
        return $this->subsiteID;
50
    }
51
52
    public function tree(HTTPRequest $request)
53
    {
54
        $results = SubsiteState::singleton()->withState(function () use ($request) {
55
            SubsiteState::singleton()->setSubsiteId($this->subsiteID);
56
            return parent::tree($request);
57
        });
58
59
        return $results;
60
    }
61
}
62