2017-11-30 00:28:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace SilverStripe\CMS\Model;
|
|
|
|
|
|
|
|
use SilverStripe\Assets\File;
|
2018-01-16 04:53:11 +01:00
|
|
|
use SilverStripe\Forms\FieldList;
|
2017-11-30 00:28:19 +01:00
|
|
|
use SilverStripe\Forms\ReadonlyField;
|
2018-01-16 04:53:11 +01:00
|
|
|
use SilverStripe\Forms\Tab;
|
|
|
|
use SilverStripe\Forms\TabSet;
|
2017-11-30 00:28:19 +01:00
|
|
|
use SilverStripe\ORM\DataExtension;
|
2018-01-16 04:53:11 +01:00
|
|
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
2017-11-30 00:28:19 +01:00
|
|
|
|
|
|
|
/**
|
2018-01-16 04:53:11 +01:00
|
|
|
* Extension applied to {@see FileFormFactory} to decorate with a "Used on:" information area.
|
|
|
|
* Uses tracking provided by {@see SiteTreeFileExtension} to generate this.
|
2017-11-30 00:28:19 +01:00
|
|
|
*
|
|
|
|
* @property File $owner
|
|
|
|
*/
|
|
|
|
class SiteTreeFileFormFactoryExtension extends DataExtension
|
|
|
|
{
|
2018-01-16 04:53:11 +01:00
|
|
|
public function updateFormFields(FieldList $fields, $controller, $formName, $context)
|
2017-11-30 00:28:19 +01:00
|
|
|
{
|
2018-01-16 04:53:11 +01:00
|
|
|
// Create field
|
|
|
|
/** @var File|SiteTreeFileExtension $record */
|
2017-11-30 00:28:19 +01:00
|
|
|
$record = $context['Record'];
|
2018-01-16 04:53:11 +01:00
|
|
|
$usedOnField = ReadonlyField::create(
|
|
|
|
'BackLinkCount',
|
|
|
|
_t(__CLASS__.'.BACKLINKCOUNT', 'Used on:'),
|
|
|
|
$record->BackLinkTrackingCount() . ' ' . _t(__CLASS__.'.PAGES', 'page(s)')
|
|
|
|
)
|
|
|
|
->addExtraClass('cms-description-toggle');
|
|
|
|
|
|
|
|
// Add table
|
|
|
|
/** @var DBHTMLText $backlinkHTML */
|
|
|
|
$backlinkHTML = $record->BackLinkHTMLList();
|
|
|
|
if (trim($backlinkHTML->forTemplate())) {
|
|
|
|
$usedOnField->setDescription($backlinkHTML);
|
|
|
|
}
|
2017-11-30 00:28:19 +01:00
|
|
|
|
2018-01-16 04:53:11 +01:00
|
|
|
/** @var TabSet $tabset */
|
|
|
|
$tabset = $fields->fieldByName('Editor');
|
2018-01-30 22:45:31 +01:00
|
|
|
if ($tabset) {
|
|
|
|
// Add field to new tab
|
|
|
|
/** @var Tab $tab */
|
|
|
|
$tab = Tab::create('Usage', _t(__CLASS__.'.USAGE', 'Usage'), $usedOnField);
|
|
|
|
$tabset->push($tab);
|
|
|
|
}
|
2017-11-30 00:28:19 +01:00
|
|
|
}
|
|
|
|
}
|