Issue #2884947: Add a shortcut configuration form for Google Maps API key
This commit is contained in:
parent
6352fdf8eb
commit
c207e3ee2f
|
@ -18,7 +18,7 @@ function farm_map_default_openlayers_sources() {
|
|||
$ol_source->description = '';
|
||||
$ol_source->factory_service = 'openlayers.Source:GoogleMaps';
|
||||
$ol_source->options = array(
|
||||
'key' => '',
|
||||
'key' => variable_get('farm_map_google_api_key', ''),
|
||||
'client' => '',
|
||||
'channel' => '',
|
||||
'mapTypeId' => 'HYBRID',
|
||||
|
@ -34,7 +34,7 @@ function farm_map_default_openlayers_sources() {
|
|||
$ol_source->description = '';
|
||||
$ol_source->factory_service = 'openlayers.Source:GoogleMaps';
|
||||
$ol_source->options = array(
|
||||
'key' => '',
|
||||
'key' => variable_get('farm_map_google_api_key', ''),
|
||||
'client' => '',
|
||||
'channel' => '',
|
||||
'mapTypeId' => 'SATELLITE',
|
||||
|
@ -50,7 +50,7 @@ function farm_map_default_openlayers_sources() {
|
|||
$ol_source->description = '';
|
||||
$ol_source->factory_service = 'openlayers.Source:GoogleMaps';
|
||||
$ol_source->options = array(
|
||||
'key' => '',
|
||||
'key' => variable_get('farm_map_google_api_key', ''),
|
||||
'client' => '',
|
||||
'channel' => '',
|
||||
'mapTypeId' => 'TERRAIN',
|
||||
|
|
|
@ -12,4 +12,20 @@ function farm_map_uninstall() {
|
|||
// Delete variables.
|
||||
variable_del('farm_map_show');
|
||||
variable_del('farm_map_default_base_layer');
|
||||
variable_del('farm_map_google_api_key');
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the Google Maps API key into the new configuration variable.
|
||||
*/
|
||||
function farm_map_update_7000(&$sandbox) {
|
||||
|
||||
// Load the Google Hybrid source.
|
||||
$source = \Drupal\openlayers\Openlayers::load('Source', 'farm_map_source_google_hybrid');
|
||||
|
||||
// If an API key is set, copy it to the variable.
|
||||
$key = $source->getOption('key');
|
||||
if (!empty($key)) {
|
||||
variable_set('farm_map_google_api_key', $key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,14 @@ function farm_map_settings_form($form, &$form_state) {
|
|||
'#default_value' => variable_get('farm_map_default_base_layer', 'farm_map_layer_google_hybrid'),
|
||||
);
|
||||
|
||||
// Google Maps API key.
|
||||
$form['farm_map_google_api_key'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Google Maps API Key'),
|
||||
'#description' => t('Google Maps layers requires that you obtain an API key. Refer to the <a href="@doc">Google Maps API Key</a> documentation on farmOS.org for instructions.', array('@doc' => 'http://farmos.org/hosting/googlemaps')),
|
||||
'#default_value' => variable_get('farm_map_google_api_key', ''),
|
||||
);
|
||||
|
||||
// Add a custom submit function to clear the Drupal cache on submission.
|
||||
$form['#submit'][] = 'farm_map_settings_form_submit';
|
||||
|
||||
|
|
Loading…
Reference in New Issue