updateCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 18
rs 9.8333
1
<?php
2
3
namespace Ichaber\SSSwiftype\Extensions;
4
5
use SilverStripe\Forms\CheckboxField;
6
use SilverStripe\Forms\FieldList;
7
use SilverStripe\Forms\LiteralField;
8
use SilverStripe\Forms\TextField;
9
use SilverStripe\ORM\DataExtension;
10
11
/**
12
 * Some default things to set up
13
 *
14
 * Class SwiftypeSiteConfigFieldsExtension
15
 *
16
 * @package Ichaber\SSSwiftype\Extensions
17
 * @property bool $SwiftypeEnabled
18
 * @property string $SwiftypeAccessKey
19
 * @property string $SwiftypeAPIKey
20
 * @property string $SwiftypeEngineKey
21
 * @property string $SwiftypeDomainID
22
 * @property string $SwiftypeEngineSlug
23
 */
24
class SwiftypeSiteConfigFieldsExtension extends DataExtension
25
{
26
    /**
27
     * @var array $db
28
     */
29
    private static $db = [
30
        'SwiftypeEnabled' => 'Boolean',
31
        'SwiftypeAccessKey' => 'Varchar(255)',
32
        'SwiftypeAPIKey' => 'Varchar(255)',
33
        'SwiftypeEngineKey' => 'Varchar(255)',
34
        'SwiftypeDomainID' => 'Varchar(255)',
35
        'SwiftypeEngineSlug' => 'Varchar(255)',
36
    ];
37
38
    /**
39
     * Settings and CMS form fields for CMS the admin/settings area
40
     *
41
     * @codeCoverageIgnore
42
     * @param FieldList $fields
43
     * @return void
44
     */
45
    public function updateCMSFields(FieldList $fields): void
46
    {
47
        // Swiftype Search Tab
48
        $fields->addFieldsToTab(
49
            'Root.SwiftypeSearch',
50
            [
51
                LiteralField::create(
52
                    '',
53
                    '<h3>Swiftype Search Settings</h3>
54
                    <h4>This is a danger zone! Do not change anything here unless you know what you are doing.</h4>'
55
                ),
56
                CheckboxField::create('SwiftypeEnabled', 'Swiftype Search Enabled')
57
                    ->setDescription('Turning this off will mean that search is disabled and JS will not be loaded.'),
58
                TextField::create('SwiftypeAPIKey', 'Swiftype API Key'),
59
                TextField::create('SwiftypeEngineSlug', 'Swiftype Engine Slug'),
60
                TextField::create('SwiftypeEngineKey', 'Swiftype Engine Key'),
61
                TextField::create('SwiftypeDomainID', 'Swiftype Domain ID'),
62
                TextField::create('SwiftypeAccessKey', 'Swiftype Access Key'),
63
            ]
64
        );
65
    }
66
}
67