silverstripe-mapboxfield/src/SiteConfigExtension.php

41 lines
924 B
PHP
Raw Normal View History

2019-09-07 02:57:59 +02:00
<?php
namespace A2nt\SilverStripeMapboxField;
use SilverStripe\Core\Extension;
2022-06-16 00:27:59 +02:00
use SilverStripe\Core\Config\Config;
2019-09-07 02:57:59 +02:00
class SiteConfigExtension extends Extension
{
public function MapAPIKey()
{
return MapboxField::getAccessToken();
}
2022-06-16 00:25:09 +02:00
2022-06-16 00:26:25 +02:00
public function MapAPIKeyFrontend(): string
2022-06-16 00:25:09 +02:00
{
$type = $this->owner->config()->get('map_type');
switch ($type) {
case 'mapbox':
$key = MapboxField::getAccessToken();
break;
case 'google-maps':
$cfg = Config::inst()->get(GoogleMapField::class, 'default_options');
2022-06-16 00:37:46 +02:00
$key = isset($cfg['api_key']) ? $cfg['api_key'] : '';
2022-06-16 00:25:09 +02:00
break;
default:
$key = '';
break;
}
return $key;
}
2019-09-07 02:57:59 +02:00
public function MapStyle()
{
return MapboxField::config()->get('map_style');
}
}