File Form missing CMS Usage information

This commit is contained in:
Mike Cochrane 2017-11-29 23:28:19 +00:00 committed by Damian Mooyman
parent d677760b24
commit 8b19afe235
4 changed files with 66 additions and 39 deletions

View File

@ -7,6 +7,9 @@ SilverStripe\Admin\LeftAndMain:
SilverStripe\Assets\File:
extensions:
- SilverStripe\CMS\Model\SiteTreeFileExtension
SilverStripe\AssetAdmin\Forms\FileFormFactory:
extensions:
- SilverStripe\CMS\Model\SiteTreeFileFormFactoryExtension
---
Name: cmsmodals
---

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,38 @@
<?php
namespace SilverStripe\CMS\Model;
use SilverStripe\Assets\File;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Versioned\Versioned;
/**
* Extension applied to {@see FileFormFactoryExtension} object to track links to {@see SiteTree} records.
*
* {@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
*/
class SiteTreeFileFormFactoryExtension extends DataExtension
{
public function updateForm($form, $controller, $name, $context)
{
$record = $context['Record'];
$fields = $form->Fields();
$fields->insertAfter(
'LastEdited',
ReadonlyField::create(
'BackLinkCount',
_t(__CLASS__.'.BACKLINKCOUNT', 'Used on:'),
$record->BackLinkTrackingCount() . ' ' . _t(__CLASS__.'.PAGES', 'page(s)')
)
->addExtraClass('cms-description-toggle')
->setDescription($record->BackLinkHTMLList())
);
}
}

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 %>