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'
|
||||
);
|
||||
|
||||
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.
|
||||
*
|
||||
|
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);
|
||||
}
|
||||
}
|
@ -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 %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user