Passed
Pull Request — master (#56)
by Marco
17:30 queued 07:16
created

SearchAdmin::getEditForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 2
dl 0
loc 17
ccs 0
cts 0
cp 0
crap 6
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Firesphere\SolrSearch\Admins;
4
5
use Firesphere\SolrSearch\Models\DirtyClass;
6
use Firesphere\SolrSearch\Models\ElevatedItem;
7
use Firesphere\SolrSearch\Models\Elevation;
8
use Firesphere\SolrSearch\Models\SolrLog;
9
use SilverStripe\Admin\ModelAdmin;
10
use SilverStripe\Forms\GridField\GridField;
11
use SilverStripe\View\Requirements;
12
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
13
14
/**
15
 * Class \Firesphere\SolrSearch\Admins\SearchAdmin
16
 * Manage or see the Solr configuration. Default implementation of SilverStripe ModelAdmin
17
 * Nothing to see here
18
 *
19
 * @package Firesphere\SolrSearch\Admins
20
 */
21
class SearchAdmin extends ModelAdmin
22
{
23
    /**
24
     * Models managed by this admin
25
     *
26
     * @var array
27
     */
28
    private static $managed_models = [
29
        SolrLog::class,
30
        DirtyClass::class,
31
        Elevation::class,
32
    ];
33
34
    /**
35
     * Add a pretty magnifying glass to the sidebar menu
36
     *
37
     * @var string
38
     */
39
    private static $menu_icon_class = 'font-icon-search';
40
41
    /**
42
     * Where to find me
43
     *
44
     * @var string
45
     */
46
    private static $url_segment = 'searchadmin';
47
48
    /**
49
     * My name
50
     *
51
     * @var string
52
     */
53 1
    private static $menu_title = 'Search';
54
55 1
    /**
56
     * Make sure the custom CSS for highlighting in the GridField is loaded
57 1
     */
58 1
    public function init()
59
    {
60
        parent::init();
61
        Requirements::css('firesphere/solr-search:client/dist/main.css');
62
        Requirements::javascript('firesphere/solr-search: client/dist/bundle.js');
63
    }
64
65
    public function getEditForm($id = null, $fields = null)
66
    {
67
        $oldImportFrom = $this->showImportForm;
68
        $this->showImportForm = false;
69
        /** @var GridField $gridField */
70
        $form = parent::getEditForm($id, $fields);
71
        $this->showImportForm = $oldImportFrom;
72
73
        if ($this->modelClass === ElevatedItem::class) {
74
            $gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));
75
76
            $gridField
77
                ->getConfig()
78
                ->addComponent(new GridFieldOrderableRows('Rank'));
79
        }
80
81
        return $form;
82
    }
83
}
84