silverstripe /
silverstripe-versioned-admin
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace SilverStripe\VersionedAdmin\Extensions; |
||||||
| 4 | |||||||
| 5 | use SilverStripe\Assets\AssetControlExtension; |
||||||
| 6 | use SilverStripe\Assets\File; |
||||||
| 7 | use SilverStripe\Core\Config\Config; |
||||||
| 8 | use SilverStripe\Forms\GridField\GridFieldDataColumns; |
||||||
| 9 | use SilverStripe\ORM\DataExtension; |
||||||
| 10 | use SilverStripe\ORM\FieldType\DBDatetime; |
||||||
| 11 | use SilverStripe\Versioned\GridFieldRestoreAction; |
||||||
| 12 | use SilverStripe\VersionedAdmin\ArchiveAdmin; |
||||||
| 13 | use SilverStripe\VersionedAdmin\Forms\GridField\GridFieldFileRestoreAction; |
||||||
| 14 | use SilverStripe\VersionedAdmin\Interfaces\ArchiveViewProvider; |
||||||
| 15 | |||||||
| 16 | /** |
||||||
| 17 | * Adds a archive view for Files |
||||||
| 18 | */ |
||||||
| 19 | class FileArchiveExtension extends DataExtension implements ArchiveViewProvider |
||||||
| 20 | { |
||||||
| 21 | /** |
||||||
| 22 | * @inheritDoc |
||||||
| 23 | */ |
||||||
| 24 | public function getArchiveFieldClass() |
||||||
| 25 | { |
||||||
| 26 | return File::class; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | /** |
||||||
| 30 | * @inheritDoc |
||||||
| 31 | */ |
||||||
| 32 | public function getArchiveField() |
||||||
| 33 | { |
||||||
| 34 | $listField = ArchiveAdmin::createArchiveGridField('Files', File::class); |
||||||
| 35 | |||||||
| 36 | $list = $listField->getList(); |
||||||
| 37 | // Paginator reports all records even if some can't be viewed, so we filter them out here |
||||||
| 38 | $list = $list->filterByCallback(function ($item) { |
||||||
|
0 ignored issues
–
show
The method
filterByCallback() does not exist on SilverStripe\ORM\SS_List. It seems like you code against a sub-type of said class. However, the method does not exist in SilverStripe\ORM\Sortable or SilverStripe\ORM\Limitable. Are you sure you never get one of those?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 39 | return $item->canView(); |
||||||
| 40 | }); |
||||||
| 41 | $listField->setList($list); |
||||||
| 42 | $listConfig = $listField->getConfig(); |
||||||
| 43 | $listConfig->removeComponentsByType(GridFieldRestoreAction::class); |
||||||
| 44 | $listConfig->addComponent(new GridFieldFileRestoreAction()); |
||||||
| 45 | |||||||
| 46 | $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class); |
||||||
| 47 | $listColumns->setDisplayFields([ |
||||||
|
0 ignored issues
–
show
The method
setDisplayFields() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldDataColumns or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 48 | 'Name' => File::singleton()->fieldLabel('Name'), |
||||||
| 49 | 'appCategory' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_TYPE', 'Type'), |
||||||
| 50 | 'Versions.first.LastEdited' => _t( |
||||||
| 51 | 'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_DATEARCHIVED', |
||||||
| 52 | 'Date Archived' |
||||||
| 53 | ), |
||||||
| 54 | 'Parent.Name' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ORIGIN', 'Origin'), |
||||||
| 55 | 'Versions.first.Author.Name' => _t( |
||||||
| 56 | 'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ARCHIVEDBY', |
||||||
| 57 | 'Archived By' |
||||||
| 58 | ) |
||||||
| 59 | ]); |
||||||
| 60 | $listColumns->setFieldFormatting([ |
||||||
|
0 ignored issues
–
show
The method
setFieldFormatting() does not exist on SilverStripe\Forms\GridField\GridFieldComponent. It seems like you code against a sub-type of SilverStripe\Forms\GridField\GridFieldComponent such as SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\GridField\GridFieldDataColumns or SilverStripe\Forms\GridField\GridFieldPrintButton or SilverStripe\Forms\Tests...ndlerTest\TestComponent or SilverStripe\Forms\GridField\GridFieldDetailForm.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 61 | 'appCategory' => function ($val, $item) { |
||||||
| 62 | return ucfirst($val ?: $item->i18n_singular_name()); |
||||||
| 63 | }, |
||||||
| 64 | 'Versions.first.LastEdited' => function ($val, $item) { |
||||||
|
0 ignored issues
–
show
The parameter
$item is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||||
| 65 | return DBDatetime::create_field('Datetime', $val)->Ago(); |
||||||
| 66 | }, |
||||||
| 67 | ]); |
||||||
| 68 | |||||||
| 69 | return $listField; |
||||||
| 70 | } |
||||||
| 71 | |||||||
| 72 | /** |
||||||
| 73 | * The files archive is only useful if archived assets are stored |
||||||
| 74 | * so this checks if this option is enabled |
||||||
| 75 | * |
||||||
| 76 | * @return boolean |
||||||
| 77 | */ |
||||||
| 78 | public function isArchiveFieldEnabled() |
||||||
| 79 | { |
||||||
| 80 | return Config::inst()->get(AssetControlExtension::class, 'keep_archived_assets'); |
||||||
| 81 | } |
||||||
| 82 | } |
||||||
| 83 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: