GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#111)
by
unknown
02:39
created

BlockAdmin   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 68
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getManagedModels() 0 11 2
A getEditForm() 0 16 2
A getSearchContext() 0 13 3
1
<?php
2
3
namespace SheaDawson\Blocks\controllers;
4
5
use SilverStripe\Admin\ModelAdmin;
6
use SilverStripe\ORM\Versioning\Versioned;
7
8
/**
9
 * BlockAdmin.
10
 *
11
 * @author Shea Dawson <[email protected]>
12
 */
13
class BlockAdmin extends ModelAdmin
14
{
15
    private static $managed_models = array(
0 ignored issues
show
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...
16
        "SheaDawson\Blocks\model\Block",
17
        "SheaDawson\Blocks\model\BlockSet",
18
    );
19
20
    private static $url_segment = "block-admin";
0 ignored issues
show
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...
21
22
    private static $menu_title = "Blocks";
0 ignored issues
show
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...
23
24
    public $showImportForm = false;
25
26
    private static $dependencies = array(
0 ignored issues
show
Unused Code introduced by
The property $dependencies 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...
27
        "blockManager" => '%$blockManager',
28
    );
29
30
    public $blockManager;
31
32
    /**
33
     * @return array
34
     **/
35
    public function getManagedModels()
36
    {
37
        $models = parent::getManagedModels();
38
39
        // remove blocksets if not in use (set in config):
40
        if (!$this->blockManager->getUseBlockSets()) {
41
            unset($models['BlockSet']);
42
        }
43
44
        return $models;
45
    }
46
47
    /**
48
     * @return Form
49
     **/
50
    public function getEditForm($id = null, $fields = null)
51
    {
52
        Versioned::reading_stage('Stage');
53
        $form = parent::getEditForm($id, $fields);
54
55
        if ($blockGridField = $form->Fields()->fieldByName('Block')) {
56
            $blockGridField->setConfig(GridFieldConfig_BlockManager::create(true, true, false));
57
            $config = $blockGridField->getConfig();
58
            $dcols = $config->getComponentByType('GridFieldDataColumns');
59
            $dfields = $dcols->getDisplayFields($blockGridField);
60
            unset($dfields['BlockArea']);
61
            $dcols->setDisplayFields($dfields);
62
        }
63
64
        return $form;
65
    }
66
67
    public function getSearchContext()
68
    {
69
        $context = parent::getSearchContext();
70
        $fields = $context->getFields();
71
        $subclasses = $this->blockManager->getBlockClasses();
72
        if ($fields->dataFieldByName('q[ClassName]') && sizeof($subclasses) > 1) {
73
            $fields->dataFieldByName('q[ClassName]')->setSource($subclasses);
74
            $fields->dataFieldByName('q[ClassName]')->setEmptyString('(any)');
75
        } else {
76
            $fields->removeByName('q[ClassName]');
77
        }
78
        return $context;
79
    }
80
}
81