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

CwpSiteTreeFileExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A BackLinkHTMLList() 0 17 2
A updateCMSFields() 0 12 1
1
<?php
2
class CwpSiteTreeFileExtension extends DataExtension {
3
4
	public function updateCMSFields(FieldList $fields) {
5
		Requirements::css('cwp/css/fieldDescriptionToggle.css');
6
		Requirements::javascript('cwp/javascript/fieldDescriptionToggle.js');
7
8
		$fields->insertAfter(
9
			ReadonlyField::create(
10
				'BackLinkCount', 
11
				_t('AssetTableField.BACKLINKCOUNT', 'Used on:'), 
12
				$this->owner->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)'))
13
			->addExtraClass('cms-description-toggle')
14
			->setDescription($this->BackLinkHTMLList()),
15
			'LastEdited'
0 ignored issues
show
Bug introduced by
'LastEdited' of type string is incompatible with the type FormField expected by parameter $item of FieldList::insertAfter(). ( Ignorable by Annotation )

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

15
			/** @scrutinizer ignore-type */ 'LastEdited'
Loading history...
16
		);
17
	}
18
19
	/**
20
	 * Generate an HTML list which provides links to where a file is used.
21
	 *
22
	 * @return String
23
	 */
24
	public function BackLinkHTMLList() {
25
		$html = '<em>' . _t('SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION', 'This list shows all pages where the file has been added through a WYSIWYG editor.') . '</em>';
26
		$html .= '<ul>';
27
28
		foreach ($this->owner->BackLinkTracking() as $backLink) {
29
			$listItem = '<li>';
30
31
			// Add the page link
32
			$listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' . Convert::raw2xml($backLink->MenuTitle) . '</a> &ndash; ';
0 ignored issues
show
Bug introduced by
Are you sure Convert::raw2xml($backLink->MenuTitle) of type string|array can be used in concatenation? ( Ignorable by Annotation )

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

32
			$listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' . /** @scrutinizer ignore-type */ Convert::raw2xml($backLink->MenuTitle) . '</a> &ndash; ';
Loading history...
33
34
			// Add the CMS link
35
			$listItem .= '<a href="' . $backLink->CMSEditLink() . '">' . _t('SiteTreeFileExtension.EDIT', 'Edit') . '</a>';
36
37
			$html .= $listItem . '</li>';
38
		}
39
40
		return $html .= '</ul>';
41
	}
42
43
}
44