Archiving GridField Columns

Silverstripe 4.5

Is it possible to add columns to the archive section? I need to show extra information if possible.


Here is what I am trying to achieve. Hopefully makes sense.

I am still needing help on this one :frowning:

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.

  1. via an Extension on ArchiveAdmin:
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);
                    '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'),


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

  1. If you want do different fields for more than one object, you may need to look into setting the getArchiveFields on the class. Have a look inside vendor/silverstripe/versioned-admin/src/extensions/SiteTreeArchiveExtension.php for how that is implemented.

Good luck

1 Like

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)) {
						'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'),