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 = [ |
|
|
|
|
31
|
|
|
'MarkerIconImage' => Image::class, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var array |
36
|
|
|
*/ |
37
|
|
|
private static $owns = [ |
|
|
|
|
38
|
|
|
'MarkerIconImage', |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var array |
43
|
|
|
*/ |
44
|
|
|
private static $many_many_extraFields = [ |
|
|
|
|
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) { |
|
|
|
|
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()) { |
|
|
|
|
80
|
|
|
$icon = $this->owner->Categories()->sort('Sort')->first()->MarkerIconImage(); |
81
|
|
|
return $icon->getURL(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$imageURL = ''; |
85
|
|
|
$this->owner->extend('updateMarkerIconURL', $imageURL); |
|
|
|
|
86
|
|
|
return $imageURL; |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|