Completed
Pull Request — master (#13)
by Robbie
02:33
created

CwpSiteTreeFileExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 14 1
A BackLinkHTMLList() 0 23 2
1
<?php
2
3
namespace CWP\CWP\Extensions;
4
5
use SilverStripe\Forms\FieldList;
6
use SilverStripe\View\Requirements;
7
use SilverStripe\Forms\ReadonlyField;
8
use SilverStripe\Core\Convert;
9
use SilverStripe\ORM\DataExtension;
10
11
class CwpSiteTreeFileExtension extends DataExtension
12
{
13
14
    public function updateCMSFields(FieldList $fields)
15
    {
16
        Requirements::css('cwp/css/fieldDescriptionToggle.css');
17
        Requirements::javascript('cwp/javascript/fieldDescriptionToggle.js');
18
19
        $fields->insertAfter(
20
            ReadonlyField::create(
21
                'BackLinkCount',
0 ignored issues
show
Bug introduced by
'BackLinkCount' 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

21
                /** @scrutinizer ignore-type */ 'BackLinkCount',
Loading history...
22
                _t('AssetTableField.BACKLINKCOUNT', 'Used on:'),
23
                $this->owner->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)')
24
            )
25
            ->addExtraClass('cms-description-toggle')
26
            ->setDescription($this->BackLinkHTMLList()),
27
            'LastEdited'
0 ignored issues
show
Bug introduced by
'LastEdited' of type string is incompatible with the type SilverStripe\Forms\FormField expected by parameter $item of SilverStripe\Forms\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

27
            /** @scrutinizer ignore-type */ 'LastEdited'
Loading history...
28
        );
29
    }
30
31
    /**
32
     * Generate an HTML list which provides links to where a file is used.
33
     *
34
     * @return String
35
     */
36
    public function BackLinkHTMLList()
37
    {
38
        $html = '<em>' . _t(
39
            'SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION',
40
            'This list shows all pages where the file has been added through a WYSIWYG editor.'
41
        ) . '</em>';
42
        $html .= '<ul>';
43
44
        foreach ($this->owner->BackLinkTracking() as $backLink) {
45
            $listItem = '<li>';
46
47
            // Add the page link
48
            $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">'
49
                . Convert::raw2xml($backLink->MenuTitle) . '</a> &ndash; ';
0 ignored issues
show
Bug introduced by
Are you sure SilverStripe\Core\Conver...l($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

49
                . /** @scrutinizer ignore-type */ Convert::raw2xml($backLink->MenuTitle) . '</a> &ndash; ';
Loading history...
50
51
            // Add the CMS link
52
            $listItem .= '<a href="' . $backLink->CMSEditLink() . '">'
53
                . _t('SiteTreeFileExtension.EDIT', 'Edit') . '</a>';
54
55
            $html .= $listItem . '</li>';
56
        }
57
58
        return $html .= '</ul>';
59
    }
60
}
61