1 | <?php |
||||
2 | |||||
3 | namespace DNADesign\Elemental\Extensions; |
||||
4 | |||||
5 | use SilverStripe\Admin\Forms\UsedOnTable; |
||||
6 | use SilverStripe\CMS\Model\SiteTree; |
||||
7 | use SilverStripe\ORM\DataExtension; |
||||
8 | use SilverStripe\ORM\ArrayList; |
||||
9 | use SilverStripe\ORM\DataObject; |
||||
10 | use SilverStripe\ORM\ValidationException; |
||||
11 | use DNADesign\Elemental\Models\ElementalArea; |
||||
12 | use DNADesign\Elemental\Models\BaseElement; |
||||
13 | |||||
14 | class ElementalAreaUsedOnTableExtension extends DataExtension |
||||
15 | { |
||||
16 | |||||
17 | /** |
||||
18 | * Hides ElementalArea's from the "Used On" tab when viewing files |
||||
19 | * |
||||
20 | * @var array $excludedClasses |
||||
21 | */ |
||||
22 | public function updateUsageExcludedClasses(array &$excludedClasses) |
||||
23 | { |
||||
24 | $excludedClasses[] = ElementalArea::class; |
||||
25 | } |
||||
26 | |||||
27 | /** |
||||
28 | * Legacy function kept for semver, replaced with updateUsageExcludedClasses above |
||||
29 | * |
||||
30 | * @return void |
||||
31 | * @var ArrayList $usage |
||||
32 | * @var DataObject $record |
||||
33 | * @see UsedOnTable::updateUsage |
||||
34 | * @deprecated 4.5.0 Use self::updateUsageExcludedClasses instead |
||||
35 | */ |
||||
36 | public function updateUsage(ArrayList &$usage, DataObject &$record) |
||||
0 ignored issues
–
show
The parameter
$record 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. ![]() |
|||||
37 | { |
||||
38 | // noop |
||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * Exclude content blocks that aren't linked to a page |
||||
43 | * |
||||
44 | * @param bool $excludeDataObject |
||||
45 | * @param DataObject $dataObject|null |
||||
46 | */ |
||||
47 | public function updateUsageDataObject(?DataObject &$dataObject) |
||||
48 | { |
||||
49 | if (!($dataObject instanceof BaseElement)) { |
||||
50 | return; |
||||
51 | } |
||||
52 | try { |
||||
53 | if (!$dataObject->getPage()) { |
||||
54 | $dataObject = null; |
||||
55 | } |
||||
56 | } catch (ValidationException $e) { |
||||
57 | $dataObject = null; |
||||
58 | } |
||||
59 | } |
||||
60 | |||||
61 | /** |
||||
62 | * Link BaseElement's to their parent page |
||||
63 | * |
||||
64 | * @param array $ancestorDataObjects |
||||
65 | * @param DataObject $dataObject |
||||
66 | */ |
||||
67 | public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject) |
||||
68 | { |
||||
69 | if (!($dataObject instanceof BaseElement)) { |
||||
70 | return; |
||||
71 | } |
||||
72 | try { |
||||
73 | // BaseElement::getPage() caches results so there's no performance decrease from |
||||
74 | // also calling it in updateUsageExcludeDataObject() |
||||
75 | /** @var SiteTree $page */ |
||||
76 | if ($page = $dataObject->getPage()) { |
||||
77 | $ancestorDataObjects[] = $page; |
||||
78 | } |
||||
79 | } catch (ValidationException $e) { |
||||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||||
80 | } |
||||
81 | } |
||||
82 | } |
||||
83 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.