File tree Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Expand file tree Collapse file tree 1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -115,10 +115,6 @@ public function setupOptions(array $options) {
115
115
* {@inheritdoc}
116
116
*/
117
117
public function Field ($ properties = array ()) {
118
- $ key = $ this ->options ['api_key ' ] ? "&key= " .$ this ->options ['api_key ' ] : "" ;
119
- Requirements::javascript (GOOGLEMAPFIELD_BASE .'/javascript/GoogleMapField.js ' );
120
- Requirements::javascript ("//maps.googleapis.com/maps/api/js?callback=googlemapfieldInit " .$ key );
121
- Requirements::css (GOOGLEMAPFIELD_BASE .'/css/GoogleMapField.css ' );
122
118
$ jsOptions = array (
123
119
'coords ' => array (
124
120
$ this ->recordFieldData ('Latitude ' ),
@@ -132,10 +128,26 @@ public function Field($properties = array()) {
132
128
133
129
$ jsOptions = array_replace_recursive ($ this ->options , $ jsOptions );
134
130
$ this ->setAttribute ('data-settings ' , Convert::array2json ($ jsOptions ));
135
-
131
+ $ this -> requireDependencies ();
136
132
return parent ::Field ($ properties );
137
133
}
138
134
135
+ /**
136
+ * Set up and include any frontend requirements
137
+ * @return void
138
+ */
139
+ protected function requireDependencies () {
140
+ $ gmapsParams = array (
141
+ 'callback ' => 'googlemapfieldInit ' ,
142
+ );
143
+ if ($ key = $ this ->getOption ('api_key ' )) {
144
+ $ gmapsParams ['key ' ] = $ key ;
145
+ }
146
+ Requirements::css (GOOGLEMAPFIELD_BASE .'/css/GoogleMapField.css ' );
147
+ Requirements::javascript (GOOGLEMAPFIELD_BASE .'/javascript/GoogleMapField.js ' );
148
+ Requirements::javascript ('//maps.googleapis.com/maps/api/js? ' . http_build_query ($ gmapsParams ));
149
+ }
150
+
139
151
/**
140
152
* {@inheritdoc}
141
153
*/
You can’t perform that action at this time.
0 commit comments