Passed
Push — hans/elevation-rebase ( 7406ec )
by Simon
09:40
created

SearchAdmin::getEditForm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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