MemberAdmin::getEditForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 1
eloc 12
nc 1
nop 2
1
<?php namespace StudioBonito\Security\Controllers;
2
3
use GridFieldButtonRow;
4
use GridFieldExportButton;
5
use GridFieldPrintButton;
6
7
/**
8
 * ModelAdmin implementation for handling member, group and role data-objects.
9
 *
10
 * @author       Tom Densham <[email protected]>
11
 * @copyright    Studio Bonito Ltd.
12
 */
13
class MemberAdmin extends \ModelAdmin
14
{
15
    /**
16
     * The current url segment. {@link LeftAndMain::$url_segment}
17
     *
18
     * @config
19
     * @var string
20
     */
21
    private static $url_segment = 'members';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $url_segment is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
23
    /**
24
     * The current menu title. {@link LeftAndMain::$menu_title}
25
     *
26
     * @config
27
     * @var string
28
     */
29
    private static $menu_title = 'Security';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_title is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
30
31
    /**
32
     * The menu icon.
33
     *
34
     * @config
35
     * @var string
36
     */
37
    private static $menu_icon = 'framework/admin/images/menu-icons/16x16/community.png';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_icon is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
38
39
    /**
40
     * @config
41
     * @var int
42
     */
43
    private static $menu_priority = -1;
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $menu_priority is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
44
45
    /**
46
     * List of all managed {@link DataObject}s in this interface. {@link ModelAdmin::$managed_models}
47
     *
48
     * @config
49
     * @var array|string
50
     */
51
    private static $managed_models = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $managed_models is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
52
        'Member',
53
        'Group',
54
        'PermissionRole',
55
    );
56
57
    /**
58
     * List of all {@link DataObject}s which can be imported through a subclass of {@link BulkLoader} (mostly CSV data).
59
     *
60
     * @config
61
     * @var array
62
     */
63
    private static $model_importers = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $model_importers is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
64
        'Member' => 'MemberCsvBulkLoader',
65
        'Group'  => 'GroupCsvBulkLoader',
66
    );
67
68
    /**
69
     * Override managed model labels with CMS defaults for member, group and role.
70
     *
71
     * @return array
72
     */
73
    public function getManagedModels()
74
    {
75
        $models = parent::getManagedModels();
76
77
        if (isset($models['Member']) && isset($models['Member']['title'])) {
78
            $models['Member']['title'] = _t('SecurityAdmin.Users', 'Users');
79
        }
80
81
        if (isset($models['Group']) && isset($models['Group']['title'])) {
82
            $models['Group']['title'] = singleton('Group')->i18n_plural_name();
83
        }
84
85
        if (isset($models['PermissionRole']) && isset($models['PermissionRole']['title'])) {
86
            $models['PermissionRole']['title'] = _t('SecurityAdmin.TABROLES', 'Roles');
87
        }
88
89
        return $models;
90
    }
91
92
    /**
93
     * Override gridfield configuration to provide a consistent UX.
94
     *
95
     * @param null $id
96
     * @param null $fields
97
     *
98
     * @return \CMSForm
99
     */
100
    public function getEditForm($id = null, $fields = null)
101
    {
102
        $form = parent::getEditForm($id, $fields);
103
104
        $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
105
        $gridFieldConfig = $gridField->getConfig();
106
107
        $gridFieldConfig->addComponent(new GridFieldButtonRow('after'));
108
109
        $gridFieldConfig->removeComponentsByType('GridFieldExportButton');
110
111
        $exportButton = new GridFieldExportButton('buttons-after-left');
112
        $exportButton->setExportColumns($this->getExportFields());
113
114
        $gridFieldConfig->addComponent($exportButton);
115
116
        $gridFieldConfig->removeComponentsByType('GridFieldPrintButton');
117
118
        $gridFieldConfig->addComponent(new GridFieldPrintButton('buttons-after-left'));
119
120
        return $form;
121
    }
122
}
123