Merge pull request #2044 from mikenz/asset-admin-missing-cms-usage

File Form missing CMS Usage information
This commit is contained in:
Daniel Hensby 2018-01-16 08:35:26 +00:00 committed by GitHub
commit b9755f0e82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 79 additions and 39 deletions

8
_config/asset-admin.yml Normal file
View File

@ -0,0 +1,8 @@
---
Name: cms-asset-admin
OnlyIf:
ModuleExists: silverstripe/asset-admin
---
SilverStripe\AssetAdmin\Forms\FileFormFactory:
extensions:
- SilverStripe\CMS\Model\SiteTreeFileFormFactoryExtension

View File

@ -41,20 +41,6 @@ class SiteTreeFileExtension extends DataExtension
'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.
*

View 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);
}
}

View File

@ -1,27 +1,27 @@
<% if $BackLinkTracking %>
<table class="table">
<thead>
<tr>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_INDEX '#' %></th>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_USED_ON 'Used on' %></th>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_TYPE 'Type' %></th>
</tr>
</thead>
<tbody>
<% loop $BackLinkTracking %>
<tr>
<th>$Pos</th>
<td><a href="$CMSEditLink">$MenuTitle</a></td>
<td>
$i18n_singular_name
<% if $isPublished %>
<span class="label label-success">Published</span>
<% else %>
<span class="label label-info">Draft</span>
<% end_if %>
</td>
</tr>
<% end_loop %>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_INDEX '#' %></th>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_USED_ON 'Used on' %></th>
<th><%t SilverStripe\CMS\Model\SiteTreeFileExtension.TITLE_TYPE 'Type' %></th>
</tr>
</thead>
<tbody>
<% loop $BackLinkTracking %>
<tr>
<td>$Pos</td>
<td><a href="$CMSEditLink">$MenuTitle</a></td>
<td>
$i18n_singular_name
<% if $isPublished %>
<span class="badge badge-success">Published</span>
<% else %>
<span class="badge status-addedtodraft">Draft</span>
<% end_if %>
</td>
</tr>
<% end_loop %>
</tbody>
</table>
<% end_if %>