src/VersionedGridFieldItemRequest.php
protected function addVersionedButtons(DataObject $record, FieldList $actions)
    {
        // Save & Publish action
        if ($record->canPublish()) {
            // "publish", as with "save", it supports an alternate state to show when action is needed.
            $publish = FormAction::create(
                'doPublish',
                _t(__CLASS__ . '.BUTTONPUBLISH', 'Publish')
            )
                ->setUseButtonTag(true)
                ->addExtraClass('btn btn-primary font-icon-rocket');

            // Insert after save
            if ($actions->fieldByName('action_doSave')) {
                $actions->insertAfter('action_doSave', $publish);
            } else {
                $actions->push($publish);
            }
        }

        // Unpublish action
        if ($record->isInDB() && $record->canUnpublish()) {
            /** @var DataObject|Versioned|RecursivePublishable $liveRecord */
            $liveRecord = Versioned::get_by_stage($record->baseClass(), Versioned::LIVE)
                ->byID($record->ID);
            if ($liveRecord) {
                $liveOwners = $liveRecord->findOwners(false)->count();
                $actions->push(
                    FormAction::create(
                        'doUnpublish',
                        _t(__CLASS__ . '.BUTTONUNPUBLISH', 'Unpublish')
                    )
                        ->setUseButtonTag(true)
                        ->setDescription(_t(
                            __CLASS__ . '.BUTTONUNPUBLISHDESC',
                            'Remove this record from the published site'
                        ))
                        ->addExtraClass('btn-secondary')
                        ->setAttribute('data-owners', $liveOwners)
                );
            }
        }

        // Archive action
        if ($record->isInDB() && $record->canArchive()) {
            // Replace "delete" action
            $actions->removeByName('action_doDelete');

            // "archive"
            $actions->push(
                FormAction::create('doArchive', _t(__CLASS__ . '.ARCHIVE', 'Archive'))
                    ->setUseButtonTag(true)
                    ->setDescription(_t(
                        __CLASS__ . '.BUTTONARCHIVEDESC',
                        'Unpublish and send to archive'
                    ))
                    ->addExtraClass('btn-secondary action--archive font-icon-box')
            );
        }
    }
protected function addVersionedButtons(DataObject $record, FieldList $actions)
    {
        // Save & Publish action
        if ($record->canPublish()) {
            // "publish", as with "save", it supports an alternate state to show when action is needed.
            $publish = FormAction::create(
                'doPublish',
                _t(__CLASS__ . '.BUTTONPUBLISH', 'Publish')
            )
                ->setUseButtonTag(true)
                ->addExtraClass('btn btn-primary font-icon-rocket');

            // Insert after save
            if ($actions->fieldByName('action_doSave')) {
                $actions->insertAfter('action_doSave', $publish);
            } else {
                $actions->push($publish);
            }
        }

        // Unpublish action
        if ($record->isInDB() && $record->canUnpublish()) {
            /** @var DataObject|Versioned|RecursivePublishable $liveRecord */
            $liveRecord = Versioned::get_by_stage($record->baseClass(), Versioned::LIVE)
                ->byID($record->ID);
            if ($liveRecord) {
                $liveOwners = $liveRecord->findOwners(false)->count();
                $actions->push(
                    FormAction::create(
                        'doUnpublish',
                        _t(__CLASS__ . '.BUTTONUNPUBLISH', 'Unpublish')
                    )
                        ->setUseButtonTag(true)
                        ->setDescription(_t(
                            __CLASS__ . '.BUTTONUNPUBLISHDESC',
                            'Remove this record from the published site'
                        ))
                        ->addExtraClass('btn-secondary')
                        ->setAttribute('data-owners', $liveOwners)
                );
            }
        }

        // Archive action
        if ($record->isInDB() && $record->canArchive()) {
            // Replace "delete" action
            $actions->removeByName('action_doDelete');

            // "archive"
            $actions->push(
                FormAction::create('doArchive', _t(__CLASS__ . '.ARCHIVE', 'Archive'))
                    ->setUseButtonTag(true)
                    ->setDescription(_t(
                        __CLASS__ . '.BUTTONARCHIVEDESC',
                        'Unpublish and send to archive'
                    ))
                    ->addExtraClass('btn-secondary action--archive font-icon-box')
            );
        }
    }
protected function addVersionedButtons ( DataObject $ record , FieldList $ actions ) { // Save & Publish action if ( $ record -> canPublish ( ) ) { // "publish", as with "save", it supports an alternate state to show when action is needed. $ publish = FormAction :: create ( 'doPublish' , _t ( __CLASS__ . '.BUTTONPUBLISH' , 'Publish' ) ) -> setUseButtonTag ( true ) -> addExtraClass ( 'btn btn-primary font-icon-rocket' ) ; // Insert after save if ( $ actions -> fieldByName ( 'action_doSave' ) ) { $ actions -> insertAfter ( 'action_doSave' , $ publish ) ; } else { $ actions -> push ( $ publish ) ; } } // Unpublish action if ( $ record -> isInDB ( ) && $ record -> canUnpublish ( ) ) { /** @var DataObject|Versioned|RecursivePublishable $liveRecord */ $ liveRecord = Versioned :: get_by_stage ( $ record -> baseClass ( ) , Versioned :: LIVE ) -> byID ( $ record -> ID ) ; if ( $ liveRecord ) { $ liveOwners = $ liveRecord -> findOwners ( false ) -> count ( ) ; $ actions -> push ( FormAction :: create ( 'doUnpublish' , _t ( __CLASS__ . '.BUTTONUNPUBLISH' , 'Unpublish' ) ) -> setUseButtonTag ( true ) -> setDescription ( _t ( __CLASS__ . '.BUTTONUNPUBLISHDESC' , 'Remove this record from the published site' ) ) -> addExtraClass ( 'btn-secondary' ) -> setAttribute ( 'data-owners' , $ liveOwners ) ) ; } } // Archive action if ( $ record -> isInDB ( ) && $ record -> canArchive ( ) ) { // Replace "delete" action $ actions -> removeByName ( 'action_doDelete' ) ; // "archive" $ actions -> push ( FormAction :: create ( 'doArchive' , _t ( __CLASS__ . '.ARCHIVE' , 'Archive' ) ) -> setUseButtonTag ( true ) -> setDescription ( _t ( __CLASS__ . '.BUTTONARCHIVEDESC' , 'Unpublish and send to archive' ) ) -> addExtraClass ( 'btn-secondary action--archive font-icon-box' ) ) ; } }
Getting buttons that are for versioned objects

@param DataObject|Versioned|RecursivePublishable $record
@param FieldList $actions
Getting buttons that are for versioned objects