Silverstripe 4.5
Is it possible to add columns to the archive section? I need to show extra information if possible.
Thanks
Silverstripe 4.5
Is it possible to add columns to the archive section? I need to show extra information if possible.
Thanks
I am still needing help on this one
I would try searching the silverstripe vendor folder for “Date Archived” to see if you can find the point in the code where that GridField is being generated. Then look for an extension point you can hook in to to modify it.
Hi, having had a brief look at the ArchiveAdmin getEditForm you should be able to do it in a couple of ways.
class ArchiveAdminExtension extends Extension {
public function updateEditForm($form)
{
if ($this->owner->modelClass === Advertisements::class) {
$gridfield = $form->Fields()->dataFieldByName('Others');
if ($gridfield instanceof GridField) {
$listColumns = $gridfield->getConfig()->getComponentByType(GridFieldDataColumns::class);
$listColumns->setDisplayFields([
'Title' => _t(__CLASS__ . '.COLUMN_TITLE', 'Title'),
/* ADD CUSTOM FIELDS */
'Description' => 'A custom title',
'allVersions.first.LastEdited' => _t(__CLASS__ . '.COLUMN_DATEARCHIVED', 'Date Archived'),
'allVersions.first.Author.Name' => _t(__CLASS__ . '.COLUMN_ARCHIVEDBY', 'Archived By'),
]);
}
}
}
config.yml:
SilverStripe\VersionedAdmin\ArchiveAdmin:
extensions:
- You\Namespace\ArchiveAdminExtension
This should set the columns for Advertisements only. If you want to display a field that exists on all other archived objects then remove the if ($this->owner->modelClass === Advertisements::class)
This isn’t tested, but should put you on the right track.
Good luck
Thankyou for your help!
This is what I ended up with after workingout the kinks.
namespace {
use SilverStripe\Core\Extension;
use SilverStripe\Forms\GridField\GridFieldDataColumns;
class ArchivesExtension extends Extension {
public function updateEditForm($form) {
if ($this->owner->modelClass === Advertisement::class) {
if ($GridField = $form->Fields()->dataFieldByName('Others')) {
if ($Header = $GridField->getConfig()->getComponentByType(GridFieldDataColumns::class)) {
$Header->setDisplayFields([
'Title' => _t(__CLASS__ . '.COLUMN_TITLE', 'Title'),
'Starts' => 'Starts',
'Ends' => 'Ends',
'Description' => 'Description',
'allVersions.first.LastEdited' => _t(__CLASS__ . '.COLUMN_DATEARCHIVED', 'Date Archived'),
'allVersions.first.Author.Name' => _t(__CLASS__ . '.COLUMN_ARCHIVEDBY', 'Archived By'),
]);
}
}
}
}
}
}