silverstripe /
silverstripe-versioned-admin
| 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 | public function getArchiveFieldClass() |
||||||
| 22 | { |
||||||
| 23 | return SiteTree::class; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 24 | } |
||||||
| 25 | |||||||
| 26 | /** |
||||||
| 27 | * @inheritDoc |
||||||
| 28 | */ |
||||||
| 29 | public function getArchiveField() |
||||||
| 30 | { |
||||||
| 31 | $listField = ArchiveAdmin::createArchiveGridField('Pages', SiteTree::class); |
||||||
| 32 | |||||||
| 33 | $listColumns = $listField->getConfig()->getComponentByType(GridFieldDataColumns::class); |
||||||
| 34 | $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...
|
|||||||
| 35 | 'Title' => SiteTree::singleton()->fieldLabel('Title'), |
||||||
| 36 | 'i18n_singular_name' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_TYPE', 'Type'), |
||||||
| 37 | 'Versions.first.LastEdited' => _t( |
||||||
| 38 | 'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_DATEARCHIVED', |
||||||
| 39 | 'Date Archived' |
||||||
| 40 | ), |
||||||
| 41 | 'ParentID' => _t('SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ORIGIN', 'Origin'), |
||||||
| 42 | 'Versions.first.Author.Name' => _t( |
||||||
| 43 | 'SilverStripe\\VersionedAdmin\\ArchiveAdmin.COLUMN_ARCHIVEDBY', |
||||||
| 44 | 'Archived By' |
||||||
| 45 | ) |
||||||
| 46 | ]); |
||||||
| 47 | $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...
|
|||||||
| 48 | 'ParentID' => 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...
|
|||||||
| 49 | if (SiteTree::get_by_id($val)) { |
||||||
| 50 | $breadcrumbs = SiteTree::get_by_id($val)->getBreadcrumbItems(2); |
||||||
| 51 | $breadcrumbString = '../'; |
||||||
| 52 | foreach ($breadcrumbs as $item) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 53 | $breadcrumbString = $breadcrumbString . $item->URLSegment . '/'; |
||||||
| 54 | }; |
||||||
| 55 | return $breadcrumbString; |
||||||
| 56 | } |
||||||
| 57 | }, |
||||||
| 58 | '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...
|
|||||||
| 59 | return DBDatetime::create_field('Datetime', $val)->Ago(); |
||||||
| 60 | }, |
||||||
| 61 | ]); |
||||||
| 62 | |||||||
| 63 | return $listField; |
||||||
| 64 | } |
||||||
| 65 | |||||||
| 66 | /** |
||||||
| 67 | * @inheritDoc |
||||||
| 68 | */ |
||||||
| 69 | public function isArchiveFieldEnabled() |
||||||
| 70 | { |
||||||
| 71 | return true; |
||||||
| 72 | } |
||||||
| 73 | } |
||||||
| 74 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: