Added a list of pages where a file is used

This commit is contained in:
David Craig 2015-04-28 12:03:07 +12:00
parent 857ade7d1d
commit 7bdca7f5cc

View File

@ -10,13 +10,41 @@ class SiteTreeFileExtension extends DataExtension {
); );
public function updateCMSFields(FieldList $fields) { public function updateCMSFields(FieldList $fields) {
$fields->insertAfter(new ReadonlyField('BackLinkCount', $fields->insertAfter(
_t('AssetTableField.BACKLINKCOUNT', 'Used on:'), ReadonlyField::create(
$this->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)')), 'BackLinkCount',
_t('AssetTableField.BACKLINKCOUNT', 'Used on:'),
$this->BackLinkTracking()->Count() . ' ' . _t('AssetTableField.PAGES', 'page(s)'))
->addExtraClass('cms-description-toggle')
->setDescription($this->BackLinkHTMLList()),
'LastEdited' 'LastEdited'
); );
} }
/**
* Generate an HTML list which provides links to where a file is used.
*
* @return String
*/
public function BackLinkHTMLList() {
$html = '<em>' . _t('SiteTreeFileExtension.BACKLINK_LIST_DESCRIPTION', 'This list shows all pages where the file has been added through a WYSIWYG editor.') . '</em>';
$html .= '<ul>';
foreach ($this->BackLinkTracking() as $backLink) {
$listItem = '<li>';
// Add the page link
$listItem .= '<a href="' . $backLink->Link() . '" target="_blank">' . Convert::raw2xml($backLink->MenuTitle) . '</a> &ndash; ';
// Add the CMS link
$listItem .= '<a href="' . $backLink->CMSEditLink() . '">' . _t('SiteTreeFileExtension.EDIT', 'Edit') . '</a>';
$html .= $listItem . '</li>';
}
return $html .= '</ul>';
}
/** /**
* Extend through {@link updateBackLinkTracking()} in your own {@link Extension}. * Extend through {@link updateBackLinkTracking()} in your own {@link Extension}.
* *