1
<?php
2

3
namespace SilverStripe\VersionedAdmin\Extensions;
4

5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Forms\GridField\GridFieldDataColumns;
7
use SilverStripe\ORM\DataExtension;
8
use SilverStripe\ORM\FieldType\DBDatetime;
9
use SilverStripe\Security\Member;
10
use SilverStripe\VersionedAdmin\ArchiveAdmin;
11
use SilverStripe\VersionedAdmin\Interfaces\ArchiveViewProvider;
12

13
/**
14
 * Adds a archive view for Pages
15
 */
16
class SiteTreeArchiveExtension extends DataExtension implements ArchiveViewProvider
17
{
18
    /**
19
     * @inheritDoc
20
    */
21 1
    public function getArchiveFieldClass()
22
    {
23 1
        return SiteTree::class;
24
    }
25

26
    /**
27
     * @inheritDoc
28
    */
29 0
    public function getArchiveField()
30
    {
31 0
        $listField = ArchiveAdmin::createArchiveGridField('Pages', SiteTree::class);
32

33 0
        $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class);
34 0
        $listColumns->setDisplayFields([
35 0
            'Title' => SiteTree::singleton()->fieldLabel('Title'),
36 0
            'i18n_singular_name' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_TYPE', 'Type'),
37 0
            'allVersions.first.LastEdited' => _t(
38 0
                'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_DATEARCHIVED',
39 0
                'Date Archived'
40
            ),
41 0
            'ParentID' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ORIGIN', 'Origin'),
42 0
            'allVersions.first.Author.Name' => _t(
43 0
                'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ARCHIVEDBY',
44 0
                'Archived By'
45
            )
46
        ]);
47 0
        $listColumns->setFieldFormatting([
48 0
            'ParentID' => function ($val, $item) {
49 0
                if (SiteTree::get_by_id($val)) {
50 0
                    $breadcrumbs = SiteTree::get_by_id($val)->getBreadcrumbItems(2);
51 0
                    $breadcrumbString = '../';
52 0
                    foreach ($breadcrumbs as $item) {
53 0
                        $breadcrumbString = $breadcrumbString . $item->URLSegment . '/';
54
                    };
55 0
                    return $breadcrumbString;
56
                }
57 0
            },
58 0
            'allVersions.first.LastEdited' => function ($val, $item) {
59 0
                return DBDatetime::create_field('Datetime', $val)->Ago();
60 0
            },
61
        ]);
62

63 0
        return $listField;
64
    }
65

66
    /**
67
     * @inheritDoc
68
    */
69 1
    public function isArchiveFieldEnabled()
70
    {
71 1
        return true;
72
    }
73
}

Read our documentation on viewing source code .

Loading