mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 06:05:56 +00:00
Merge pull request #2044 from mikenz/asset-admin-missing-cms-usage
File Form missing CMS Usage information
This commit is contained in:
commit
b9755f0e82
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
|
@ -41,20 +41,6 @@ class SiteTreeFileExtension extends DataExtension
|
|||||||
'BackLinkHTMLList' => 'HTMLFragment'
|
'BackLinkHTMLList' => 'HTMLFragment'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function updateCMSFields(FieldList $fields)
|
|
||||||
{
|
|
||||||
$fields->insertAfter(
|
|
||||||
'LastEdited',
|
|
||||||
ReadonlyField::create(
|
|
||||||
'BackLinkCount',
|
|
||||||
_t(__CLASS__.'.BACKLINKCOUNT', 'Used on:'),
|
|
||||||
$this->BackLinkTracking()->count() . ' ' . _t(__CLASS__.'.PAGES', 'page(s)')
|
|
||||||
)
|
|
||||||
->addExtraClass('cms-description-toggle')
|
|
||||||
->setDescription($this->BackLinkHTMLList())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate an HTML list which provides links to where a file is used.
|
* Generate an HTML list which provides links to where a file is used.
|
||||||
*
|
*
|
||||||
|
46
code/Model/SiteTreeFileFormFactoryExtension.php
Normal file
46
code/Model/SiteTreeFileFormFactoryExtension.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace SilverStripe\CMS\Model;
|
||||||
|
|
||||||
|
use SilverStripe\Assets\File;
|
||||||
|
use SilverStripe\Forms\FieldList;
|
||||||
|
use SilverStripe\Forms\ReadonlyField;
|
||||||
|
use SilverStripe\Forms\Tab;
|
||||||
|
use SilverStripe\Forms\TabSet;
|
||||||
|
use SilverStripe\ORM\DataExtension;
|
||||||
|
use SilverStripe\ORM\FieldType\DBHTMLText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension applied to {@see FileFormFactory} to decorate with a "Used on:" information area.
|
||||||
|
* Uses tracking provided by {@see SiteTreeFileExtension} to generate this.
|
||||||
|
*
|
||||||
|
* @property File $owner
|
||||||
|
*/
|
||||||
|
class SiteTreeFileFormFactoryExtension extends DataExtension
|
||||||
|
{
|
||||||
|
public function updateFormFields(FieldList $fields, $controller, $formName, $context)
|
||||||
|
{
|
||||||
|
// Create field
|
||||||
|
/** @var File|SiteTreeFileExtension $record */
|
||||||
|
$record = $context['Record'];
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add field to new tab
|
||||||
|
$tab = Tab::create('Usage', _t(__CLASS__.'.USAGE', 'Usage'), $usedOnField);
|
||||||
|
/** @var TabSet $tabset */
|
||||||
|
$tabset = $fields->fieldByName('Editor');
|
||||||
|
$tabset->push($tab);
|
||||||
|
}
|
||||||
|
}
|
@ -10,14 +10,14 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<% loop $BackLinkTracking %>
|
<% loop $BackLinkTracking %>
|
||||||
<tr>
|
<tr>
|
||||||
<th>$Pos</th>
|
<td>$Pos</td>
|
||||||
<td><a href="$CMSEditLink">$MenuTitle</a></td>
|
<td><a href="$CMSEditLink">$MenuTitle</a></td>
|
||||||
<td>
|
<td>
|
||||||
$i18n_singular_name
|
$i18n_singular_name
|
||||||
<% if $isPublished %>
|
<% if $isPublished %>
|
||||||
<span class="label label-success">Published</span>
|
<span class="badge badge-success">Published</span>
|
||||||
<% else %>
|
<% else %>
|
||||||
<span class="label label-info">Draft</span>
|
<span class="badge status-addedtodraft">Draft</span>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user