Completed
Push — master ( 58895a...0930e8 )
by Robbie
15s
created

CwpSearchBoostExtension   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 22 1
1
<?php
2
3
namespace CWP\CWP\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
    /**
16
     * Quality to boost the 'SearchBoost' field by.
17
     * Default boost is 2x
18
     *
19
     * @var config
0 ignored issues
show
Bug introduced by
The type CWP\CWP\Extensions\config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     * @string
21
     */
22
    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...
23
24
    private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
25
        'SearchBoost' => 'Text'
26
    );
27
28
    /**
29
     * Adds boost fields to this page
30
     *
31
     * @param FieldList $fields
32
     */
33
    public function updateCMSFields(FieldList $fields)
34
    {
35
        parent::updateCMSFields($fields);
36
37
        // Rename metafield
38
        $meta = $fields->fieldByName('Root.Main.Metadata');
39
        $meta->setTitle(_t('CwpSearchBoostExtension.PAGEINFO', 'Page info and SEO'));
40
41
        $boostTitle = _t('CwpSiteTreeSearchBoost.SearchBoost', 'Boost Keywords');
42
        $boostNote = _t(
43
            'CwpSiteTreeSearchBoost.SearchBoostNote',
44
            '(Only applies to the search results on this site e.g. not on Google search)'
45
        );
46
        $boostDescription = _t(
47
            'CwpSiteTreeSearchBoost.SearchBoostDescription',
48
            'Enter keywords separated by comma ( , ) for which to boost the ranking of this page '
49
            . 'within the search results on this site.'
50
        );
51
        $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

51
        $boostField = TextareaField::create(/** @scrutinizer ignore-type */ 'SearchBoost', $boostTitle)
Loading history...
52
            ->setRightTitle($boostNote)
53
            ->setDescription($boostDescription);
54
        $fields->insertBefore($boostField, 'MetaDescription');
0 ignored issues
show
Bug introduced by
'MetaDescription' of type string is incompatible with the type SilverStripe\Forms\FormField expected by parameter $item of SilverStripe\Forms\FieldList::insertBefore(). ( Ignorable by Annotation )

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

54
        $fields->insertBefore($boostField, /** @scrutinizer ignore-type */ 'MetaDescription');
Loading history...
55
    }
56
}
57