1 | <?php |
||||||
2 | |||||||
3 | namespace Dynamic\Locator\React\Extensions; |
||||||
4 | |||||||
5 | use Dynamic\Locator\Location; |
||||||
6 | use SilverStripe\AssetAdmin\Forms\UploadField; |
||||||
7 | use SilverStripe\Assets\Image; |
||||||
8 | use SilverStripe\Forms\FieldList; |
||||||
9 | use SilverStripe\Forms\GridField\GridField; |
||||||
10 | use SilverStripe\Forms\GridField\GridFieldSortableHeader; |
||||||
11 | use SilverStripe\ORM\DataExtension; |
||||||
12 | use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
||||||
13 | use Symbiote\GridFieldExtensions\GridFieldTitleHeader; |
||||||
14 | |||||||
15 | /** |
||||||
16 | * Class LocationExtension |
||||||
17 | * @package Dynamic\Locator\React\Extensions |
||||||
18 | * |
||||||
19 | * @property int MarkerIconImageID |
||||||
20 | * @method Image MarkerIconImage() |
||||||
21 | * |
||||||
22 | * @property-read Location|LocationExtension $owner |
||||||
23 | */ |
||||||
24 | class LocationExtension extends DataExtension |
||||||
25 | { |
||||||
26 | |||||||
27 | /** |
||||||
28 | * @var array |
||||||
29 | */ |
||||||
30 | private static $has_one = [ |
||||||
0 ignored issues
–
show
introduced
by
![]() |
|||||||
31 | 'MarkerIconImage' => Image::class, |
||||||
32 | ]; |
||||||
33 | |||||||
34 | /** |
||||||
35 | * @var array |
||||||
36 | */ |
||||||
37 | private static $owns = [ |
||||||
0 ignored issues
–
show
|
|||||||
38 | 'MarkerIconImage', |
||||||
39 | ]; |
||||||
40 | |||||||
41 | /** |
||||||
42 | * @var array |
||||||
43 | */ |
||||||
44 | private static $many_many_extraFields = [ |
||||||
0 ignored issues
–
show
|
|||||||
45 | 'Categories' => [ |
||||||
46 | 'Sort' => 'Int', |
||||||
47 | ], |
||||||
48 | ]; |
||||||
49 | |||||||
50 | /** |
||||||
51 | * @param FieldList $fields |
||||||
52 | */ |
||||||
53 | public function updateCMSFields(FieldList $fields) |
||||||
54 | { |
||||||
55 | parent::updateCMSFields($fields); |
||||||
56 | |||||||
57 | if ($this->owner->ID) { |
||||||
0 ignored issues
–
show
|
|||||||
58 | |||||||
59 | /** @var GridField $categoryField */ |
||||||
60 | $categoryField = $fields->dataFieldByName('Categories'); |
||||||
61 | $categoryField->getConfig()->removeComponentsByType([ |
||||||
62 | GridFieldSortableHeader::class, |
||||||
63 | ])->addComponents([ |
||||||
64 | new GridFieldOrderableRows(), |
||||||
65 | new GridFieldTitleHeader(), |
||||||
66 | ]); |
||||||
67 | } |
||||||
68 | } |
||||||
69 | |||||||
70 | /** |
||||||
71 | * @return Image|string |
||||||
72 | */ |
||||||
73 | public function getMarkerIcon() |
||||||
74 | { |
||||||
75 | if ($this->owner->MarkerIconImageID) { |
||||||
76 | return $this->owner->MarkerIconImage()->getURL(); |
||||||
77 | } |
||||||
78 | |||||||
79 | if ($this->owner->Categories()->count()) { |
||||||
0 ignored issues
–
show
The method
Categories() does not exist on Dynamic\Locator\React\Extensions\LocationExtension .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
80 | $icon = $this->owner->Categories()->sort('Sort')->first()->MarkerIconImage(); |
||||||
81 | return $icon->getURL(); |
||||||
82 | } |
||||||
83 | |||||||
84 | $imageURL = ''; |
||||||
85 | $this->owner->extend('updateMarkerIconURL', $imageURL); |
||||||
0 ignored issues
–
show
The method
extend() does not exist on Dynamic\Locator\React\Extensions\LocationExtension .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
86 | return $imageURL; |
||||||
87 | } |
||||||
88 | |||||||
89 | /** |
||||||
90 | * @return array |
||||||
91 | */ |
||||||
92 | public function getCategoryData($json = true) |
||||||
93 | { |
||||||
94 | if ($this->owner->Categories()->count()) { |
||||||
95 | $names = $this->owner->Categories()->map('ID', 'Name')->toArray(); |
||||||
96 | return $json ? json_encode($names) : $names; |
||||||
0 ignored issues
–
show
|
|||||||
97 | } |
||||||
98 | return $json ? json_encode([]) : []; |
||||||
0 ignored issues
–
show
|
|||||||
99 | } |
||||||
100 | } |
||||||
101 |