Skip to content

Commit 2c496d3

Browse files
committed
Add the possibility to show some of the (previously) hidden fields
1 parent 08571ce commit 2c496d3

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

_config/googlemapfield.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ BetterBrief\GoogleMapField:
1919
center:
2020
Latitude: 30
2121
Longitude: 0
22+
# optional possibility to show some of the fields
23+
#visible_fields:
24+
# - Latitude
25+
# - Longitude

src/GoogleMapField.php

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -102,44 +102,43 @@ public function setupOptions(array $options) {
102102
*/
103103
public function setupChildren() {
104104
$name = $this->getName();
105-
106-
// Create the latitude/longitude hidden fields
107-
$this->latField = HiddenField::create(
108-
$name.'[Latitude]',
109-
'Lat',
110-
$this->recordFieldData('Latitude')
111-
)->addExtraClass('googlemapfield-latfield no-change-track');
112-
113-
$this->lngField = HiddenField::create(
114-
$name.'[Longitude]',
115-
'Lng',
116-
$this->recordFieldData('Longitude')
117-
)->addExtraClass('googlemapfield-lngfield no-change-track');
118-
119-
$this->zoomField = HiddenField::create(
120-
$name.'[Zoom]',
121-
'Zoom',
122-
$this->recordFieldData('Zoom')
123-
)->addExtraClass('googlemapfield-zoomfield no-change-track');
124-
$this->boundsField = HiddenField::create(
125-
$name.'[Bounds]',
126-
'Bounds',
127-
$this->recordFieldData('Bounds')
128-
)->addExtraClass('googlemapfield-boundsfield no-change-track');
129-
$this->children = new FieldList(
130-
$this->latField,
131-
$this->lngField,
132-
$this->zoomField,
133-
$this->boundsField
134-
);
135-
136-
if($this->options['show_search_box']) {
137-
$this->children->push(
138-
TextField::create('Search')
139-
->addExtraClass('googlemapfield-searchfield')
140-
->setAttribute('placeholder', 'Search for a location')
141-
);
142-
}
105+
$visibleFields = $this->getOption('visible_fields');
106+
$getFieldType = function($field) use ($visibleFields) {
107+
return $visibleFields && is_array($visibleFields) && in_array($field, $visibleFields)
108+
? TextField::class
109+
: HiddenField::class;
110+
};
111+
112+
// Create the latitude/longitude hidden fields
113+
$this->latField = $getFieldType('Latitude')::create(
114+
$name.'[Latitude]',
115+
'Lat',
116+
$this->recordFieldData('Latitude')
117+
)->addExtraClass('googlemapfield-latfield no-change-track mb-2');
118+
119+
$this->lngField = $getFieldType('Longitude')::create(
120+
$name.'[Longitude]',
121+
'Lng',
122+
$this->recordFieldData('Longitude')
123+
)->addExtraClass('googlemapfield-lngfield no-change-track mb-2');
124+
125+
$this->zoomField = $getFieldType('Zoom')::create(
126+
$name.'[Zoom]',
127+
'Zoom',
128+
$this->recordFieldData('Zoom')
129+
)->addExtraClass('googlemapfield-zoomfield no-change-track mb-2');
130+
131+
$this->boundsField = $getFieldType('Bounds')::create(
132+
$name.'[Bounds]',
133+
'Bounds',
134+
$this->recordFieldData('Bounds')
135+
)->addExtraClass('googlemapfield-boundsfield no-change-track mb-2');
136+
$this->children = new FieldList(
137+
$this->latField,
138+
$this->lngField,
139+
$this->zoomField,
140+
$this->boundsField
141+
);
143142

144143
return $this->children;
145144
}

0 commit comments

Comments
 (0)