@@ -102,44 +102,43 @@ public function setupOptions(array $options) {
102
102
*/
103
103
public function setupChildren () {
104
104
$ 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
+ );
143
142
144
143
return $ this ->children ;
145
144
}
0 commit comments