GridFieldFileRestoreAction::getRestoreAction()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 3
eloc 3
c 1
b 1
f 0
nc 2
nop 3
dl 0
loc 7
rs 10
1
<?php
2
3
namespace SilverStripe\VersionedAdmin\Forms\GridField;
4
5
use SilverStripe\Assets\File;
6
use SilverStripe\Versioned\GridFieldRestoreAction;
7
8
/**
9
 * Extension of GridFieldRestoreAction to only show action if there is a valid file
10
 */
11
class GridFieldFileRestoreAction extends GridFieldRestoreAction
12
{
13
    /**
14
     * @inheritdoc
15
     */
16
    public function getRestoreAction($gridField, $record, $columnName)
17
    {
18
        // Only show the action if the file exists
19
        if ($record instanceof File && $record->exists()) {
20
            return parent::getRestoreAction($gridField, $record, $columnName);
21
        }
22
        return null;
23
    }
24
}
25