Passed
Push — hans/elevation ( ec80bc )
by Simon
06:00
created

SearchAdmin::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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