Completed
Push — master ( 686084...a2bb6b )
by
unknown
9s
created

CwpSearchBoostExtension::updateCMSFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
3
namespace CWP\Search\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\Forms\TextareaField;
7
use SilverStripe\ORM\DataExtension;
8
9
/**
10
 * Adds field boosting capabilities to fulltext search for pages
11
 */
12
class CwpSearchBoostExtension extends DataExtension
13
{
14
    /**
15
     * Quality to boost the 'SearchBoost' field by.
16
     * Default boost is 2x
17
     *
18
     * @config
19
     * @var string
20
     */
21
    private static $search_boost = '2';
0 ignored issues
show
introduced by
The private property $search_boost is not used, and could be removed.
Loading history...
22
23
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
24
        'SearchBoost' => 'Text',
25
    ];
26
27
    /**
28
     * Adds boost fields to this page
29
     *
30
     * @param FieldList $fields
31
     */
32
    public function updateCMSFields(FieldList $fields)
33
    {
34
        parent::updateCMSFields($fields);
35
36
        // Rename metafield
37
        $meta = $fields->fieldByName('Root.Main.Metadata');
38
        $meta->setTitle(_t(__CLASS__ . '.PAGEINFO', 'Page info and SEO'));
39
40
        $boostTitle = _t(__CLASS__ . '.SearchBoost', 'Boost Keywords');
41
        $boostNote = _t(
42
            __CLASS__ . '.SearchBoostNote',
43
            '(Only applies to the search results on this site e.g. not on Google search)'
44
        );
45
        $boostDescription = _t(
46
            __CLASS__ . '.SearchBoostDescription',
47
            'Enter keywords separated by comma ( , ) for which to boost the ranking of this page '
48
            . 'within the search results on this site.'
49
        );
50
        $boostField = TextareaField::create('SearchBoost', $boostTitle)
0 ignored issues
show
Bug introduced by
'SearchBoost' of type string is incompatible with the type array expected by parameter $args of SilverStripe\View\ViewableData::create(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        $boostField = TextareaField::create(/** @scrutinizer ignore-type */ 'SearchBoost', $boostTitle)
Loading history...
51
            ->setRightTitle($boostNote)
52
            ->setDescription($boostDescription);
53
        $fields->insertBefore('MetaDescription', $boostField);
54
    }
55
}
56