Completed
Push — master ( a201e7...17e0db )
by
unknown
10s
created

FolderFormFactoryExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
B updateFormFields() 0 27 3
1
<?php
2
3
namespace SilverStripe\Subsites\Extensions;
4
5
use SilverStripe\Core\Extension;
6
use SilverStripe\Forms\DropdownField;
7
use SilverStripe\Forms\FieldList;
8
use SilverStripe\Forms\LiteralField;
9
use SilverStripe\Subsites\Model\Subsite;
10
11
class FolderFormFactoryExtension extends Extension
12
{
13
    /**
14
     * Add subsites-specific fields to the folder editor.
15
     * @param FieldList $fields
16
     */
17
    public function updateFormFields(FieldList $fields)
18
    {
19
        $sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin');
20
        $values = [];
21
        $values[0] = _t(__CLASS__ . '.AllSitesDropdownOpt', 'All sites');
22
        foreach ($sites as $site) {
23
            $values[$site->ID] = $site->Title;
24
        }
25
        ksort($values);
26
        if ($sites) {
27
            // Dropdown needed to move folders between subsites
28
            /** @var @skipUpgrade */
29
            $dropdown = DropdownField::create(
30
                'SubsiteID',
0 ignored issues
show
Bug introduced by
'SubsiteID' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

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

30
                /** @scrutinizer ignore-type */ 'SubsiteID',
Loading history...
31
                _t(__CLASS__ . '.SubsiteFieldLabel', 'Subsite'),
32
                $values
33
            );
34
            $dropdown->addExtraClass('subsites-move-dropdown');
35
            $fields->push($dropdown);
36
            $fields->push(LiteralField::create(
37
                'Message',
38
                '<p class="message notice">' .
39
                _t(
40
                    __CLASS__ . '.SUBSITENOTICE',
41
                    'Folders and files created in the main site are accessible by all subsites.'
42
                )
43
                . '</p>'
44
            ));
45
        }
46
    }
47
}
48