mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
Refactor and cleanup SiteTreeFileFormFactoryExtension
This commit is contained in:
parent
8b19afe235
commit
cb2745c737
8
_config/asset-admin.yml
Normal file
8
_config/asset-admin.yml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
Name: cms-asset-admin
|
||||||
|
OnlyIf:
|
||||||
|
ModuleExists: silverstripe/asset-admin
|
||||||
|
---
|
||||||
|
SilverStripe\AssetAdmin\Forms\FileFormFactory:
|
||||||
|
extensions:
|
||||||
|
- SilverStripe\CMS\Model\SiteTreeFileFormFactoryExtension
|
@ -7,9 +7,6 @@ SilverStripe\Admin\LeftAndMain:
|
|||||||
SilverStripe\Assets\File:
|
SilverStripe\Assets\File:
|
||||||
extensions:
|
extensions:
|
||||||
- SilverStripe\CMS\Model\SiteTreeFileExtension
|
- SilverStripe\CMS\Model\SiteTreeFileExtension
|
||||||
SilverStripe\AssetAdmin\Forms\FileFormFactory:
|
|
||||||
extensions:
|
|
||||||
- SilverStripe\CMS\Model\SiteTreeFileFormFactoryExtension
|
|
||||||
---
|
---
|
||||||
Name: cmsmodals
|
Name: cmsmodals
|
||||||
---
|
---
|
||||||
|
@ -3,36 +3,44 @@
|
|||||||
namespace SilverStripe\CMS\Model;
|
namespace SilverStripe\CMS\Model;
|
||||||
|
|
||||||
use SilverStripe\Assets\File;
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\ReadonlyField;
|
use SilverStripe\Forms\ReadonlyField;
|
||||||
|
use SilverStripe\Forms\Tab;
|
||||||
|
use SilverStripe\Forms\TabSet;
|
||||||
use SilverStripe\ORM\DataExtension;
|
use SilverStripe\ORM\DataExtension;
|
||||||
use SilverStripe\Versioned\Versioned;
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension applied to {@see FileFormFactoryExtension} object to track links to {@see SiteTree} records.
|
* Extension applied to {@see FileFormFactory} to decorate with a "Used on:" information area.
|
||||||
*
|
* Uses tracking provided by {@see SiteTreeFileExtension} to generate this.
|
||||||
* {@see SiteTreeLinkTracking} for the extension applied to {@see SiteTree}
|
|
||||||
*
|
|
||||||
* Note that since both SiteTree and File are versioned, LinkTracking and ImageTracking will
|
|
||||||
* only be enabled for the Stage record.
|
|
||||||
*
|
*
|
||||||
* @property File $owner
|
* @property File $owner
|
||||||
*/
|
*/
|
||||||
class SiteTreeFileFormFactoryExtension extends DataExtension
|
class SiteTreeFileFormFactoryExtension extends DataExtension
|
||||||
{
|
{
|
||||||
public function updateForm($form, $controller, $name, $context)
|
public function updateFormFields(FieldList $fields, $controller, $formName, $context)
|
||||||
{
|
{
|
||||||
|
// Create field
|
||||||
|
/** @var File|SiteTreeFileExtension $record */
|
||||||
$record = $context['Record'];
|
$record = $context['Record'];
|
||||||
$fields = $form->Fields();
|
$usedOnField = ReadonlyField::create(
|
||||||
|
'BackLinkCount',
|
||||||
|
_t(__CLASS__.'.BACKLINKCOUNT', 'Used on:'),
|
||||||
|
$record->BackLinkTrackingCount() . ' ' . _t(__CLASS__.'.PAGES', 'page(s)')
|
||||||
|
)
|
||||||
|
->addExtraClass('cms-description-toggle');
|
||||||
|
|
||||||
$fields->insertAfter(
|
// Add table
|
||||||
'LastEdited',
|
/** @var DBHTMLText $backlinkHTML */
|
||||||
ReadonlyField::create(
|
$backlinkHTML = $record->BackLinkHTMLList();
|
||||||
'BackLinkCount',
|
if (trim($backlinkHTML->forTemplate())) {
|
||||||
_t(__CLASS__.'.BACKLINKCOUNT', 'Used on:'),
|
$usedOnField->setDescription($backlinkHTML);
|
||||||
$record->BackLinkTrackingCount() . ' ' . _t(__CLASS__.'.PAGES', 'page(s)')
|
}
|
||||||
)
|
|
||||||
->addExtraClass('cms-description-toggle')
|
// Add field to new tab
|
||||||
->setDescription($record->BackLinkHTMLList())
|
$tab = Tab::create('Usage', _t(__CLASS__.'.USAGE', 'Usage'), $usedOnField);
|
||||||
);
|
/** @var TabSet $tabset */
|
||||||
|
$tabset = $fields->fieldByName('Editor');
|
||||||
|
$tabset->push($tab);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user