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.

BlockAdmin::getEditForm()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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