1 | <?php |
||
2 | |||
3 | namespace CWP\CWP\Extensions; |
||
4 | |||
5 | use SilverStripe\Core\Convert; |
||
6 | use SilverStripe\Forms\FieldList; |
||
7 | use SilverStripe\Forms\ReadonlyField; |
||
8 | use SilverStripe\ORM\DataExtension; |
||
9 | use SilverStripe\View\Requirements; |
||
10 | |||
11 | class CwpSiteTreeFileExtension extends DataExtension |
||
12 | { |
||
13 | |||
14 | public function updateCMSFields(FieldList $fields) |
||
15 | { |
||
16 | Requirements::css('cwp/cwp:css/fieldDescriptionToggle.css'); |
||
17 | Requirements::javascript('cwp/cwp:javascript/fieldDescriptionToggle.js'); |
||
18 | |||
19 | $fields->insertAfter( |
||
20 | 'LastEdited', |
||
21 | ReadonlyField::create( |
||
22 | 'BackLinkCount', |
||
23 | _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.BACKLINKCOUNT', 'Used on:'), |
||
24 | $this->owner->BackLinkTracking()->Count() . ' ' |
||
25 | . _t('SilverStripe\\CMS\\Model\\SiteTreeFileExtension.PAGES', 'page(s)') |
||
26 | ) |
||
27 | ->addExtraClass('cms-description-toggle') |
||
28 | ->setDescription($this->BackLinkHTMLList()) |
||
29 | ); |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * Generate an HTML list which provides links to where a file is used. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function BackLinkHTMLList() |
||
38 | { |
||
39 | $html = '<em>' . _t( |
||
40 | __CLASS__ . '.BACKLINK_LIST_DESCRIPTION', |
||
41 | 'This list shows all pages where the file has been added through a WYSIWYG editor.' |
||
42 | ) . '</em>'; |
||
43 | $html .= '<ul>'; |
||
44 | |||
45 | foreach ($this->owner->BackLinkTracking() as $backLink) { |
||
46 | $listItem = '<li>'; |
||
47 | |||
48 | // Add the page link |
||
49 | $listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' |
||
50 | . Convert::raw2xml($backLink->MenuTitle) . '</a> – '; |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
51 | |||
52 | // Add the CMS link |
||
53 | $listItem .= '<a href="' . $backLink->CMSEditLink() . '">' |
||
54 | . _t(__CLASS__ . '.EDIT', 'Edit') . '</a>'; |
||
55 | |||
56 | $html .= $listItem . '</li>'; |
||
57 | } |
||
58 | |||
59 | $html .= '</ul>'; |
||
60 | |||
61 | return $html; |
||
62 | } |
||
63 | } |
||
64 |