Passed
Push — master ( d7fd6a...9124ff )
by Robbie
11:58
created

CwpSearchBoostExtension   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 17 1
1
<?php
2
3
/**
4
 * Adds field boosting capabilities to fulltext search for pages
5
 */
6
class CwpSearchBoostExtension extends DataExtension {
7
	
8
	/**
9
	 * Quality to boost the 'SearchBoost' field by.
10
	 * Default boost is 2x
11
	 *
12
	 * @var config
13
	 * @string 
14
	 */
15
	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...
16
	
17
	private static $db = array(
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
18
		'SearchBoost' => 'Text'
19
	);
20
21
	/**
22
	 * Adds boost fields to this page
23
	 *
24
	 * @param FieldList $fields
25
	 */
26
	public function updateCMSFields(FieldList $fields) {
27
		parent::updateCMSFields($fields);
28
		
29
		// Rename metafield
30
		$meta = $fields->fieldByName('Root.Main.Metadata');
31
		$meta->setTitle(_t('CwpSearchBoostExtension.PAGEINFO', 'Page info and SEO'));
32
		
33
		$boostTitle = _t('CwpSiteTreeSearchBoost.SearchBoost', 'Boost Keywords');
34
		$boostNote = _t('CwpSiteTreeSearchBoost.SearchBoostNote', '(Only applies to the search results on this site e.g. not on Google search)');
35
		$boostDescription = _t(
36
			'CwpSiteTreeSearchBoost.SearchBoostDescription',
37
			'Enter keywords separated by comma ( , ) for which to boost the ranking of this page within the search results on this site.'
38
		);
39
		$boostField = TextareaField::create('SearchBoost', $boostTitle)
40
			->setRightTitle($boostNote)
41
			->setDescription($boostDescription);
42
		$fields->insertBefore($boostField, 'MetaDescription');
0 ignored issues
show
Bug introduced by
'MetaDescription' of type string is incompatible with the type FormField expected by parameter $item of 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

42
		$fields->insertBefore($boostField, /** @scrutinizer ignore-type */ 'MetaDescription');
Loading history...
43
	}
44
}
45