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