2019-12-09 11:47:17 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: tony
|
|
|
|
* Date: 6/30/18
|
|
|
|
* Time: 11:54 PM
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Site\Elements;
|
|
|
|
|
|
|
|
use A2nt\SilverStripeMapboxField\MapboxField;
|
2019-12-11 03:30:39 +01:00
|
|
|
use BetterBrief\GoogleMapField;
|
2019-12-09 11:47:17 +01:00
|
|
|
use DNADesign\Elemental\Models\ElementContent;
|
2019-12-11 03:30:39 +01:00
|
|
|
use SilverStripe\Core\Config\Config;
|
|
|
|
use SilverStripe\Forms\FieldList;
|
|
|
|
use SilverStripe\Forms\GridField\GridField;
|
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
|
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField;
|
|
|
|
use SilverStripe\Forms\NumericField;
|
2019-12-09 11:47:17 +01:00
|
|
|
use Site\Controllers\MapElementController;
|
|
|
|
use Site\Extensions\MapExtension;
|
2020-01-22 10:46:53 +01:00
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
2019-12-09 11:47:17 +01:00
|
|
|
|
|
|
|
class MapElement extends ElementContent
|
|
|
|
{
|
|
|
|
private static $icon = 'font-icon-globe-1';
|
|
|
|
|
|
|
|
private static $singular_name = 'Map Element';
|
|
|
|
|
|
|
|
private static $plural_name = 'Map Element';
|
|
|
|
|
|
|
|
private static $description = 'Displays dynamic map';
|
|
|
|
|
|
|
|
private static $table_name = 'MapElement';
|
|
|
|
|
|
|
|
private static $controller_class = MapElementController::class;
|
2019-12-11 03:30:39 +01:00
|
|
|
private static $map_type = 'mapbox';
|
2019-12-09 11:47:17 +01:00
|
|
|
|
|
|
|
private static $extensions = [
|
|
|
|
MapExtension::class,
|
|
|
|
];
|
|
|
|
|
2019-12-11 03:30:39 +01:00
|
|
|
public function getType():string
|
2019-12-09 11:47:17 +01:00
|
|
|
{
|
|
|
|
return self::$singular_name;
|
|
|
|
}
|
|
|
|
|
2019-12-11 03:30:39 +01:00
|
|
|
public function getCMSFields(): FieldList
|
2019-12-09 11:47:17 +01:00
|
|
|
{
|
|
|
|
$fields = parent::getCMSFields();
|
|
|
|
|
2019-12-11 03:30:39 +01:00
|
|
|
$fields->remove('HTML');
|
|
|
|
|
|
|
|
$tab = $fields->findOrMakeTab('Root.MapPins');
|
|
|
|
$tab->setTitle('Description');
|
|
|
|
$tab->push(HTMLEditorField::create('HTML', 'Content'));
|
|
|
|
|
|
|
|
$fields->addFieldsToTab('Root.Main', [
|
|
|
|
NumericField::create('MapZoom', 'Initial Map Zoom (enter a number from 0 to 24)'),
|
|
|
|
GridField::create(
|
|
|
|
'Locations',
|
|
|
|
'Locations',
|
|
|
|
$this->owner->Locations(),
|
2020-01-22 10:46:53 +01:00
|
|
|
$cfg = GridFieldConfig_RelationEditor::create(100)
|
2019-12-11 03:30:39 +01:00
|
|
|
)
|
|
|
|
]);
|
2019-12-09 11:47:17 +01:00
|
|
|
|
2020-01-22 10:46:53 +01:00
|
|
|
$cfg->getComponentByType(GridFieldDataColumns::class)->setFieldFormatting([
|
|
|
|
'ShowAtMap' => static function ($v, $obj) {
|
|
|
|
return $v ? 'YES' : 'NO';
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
2019-12-09 11:47:17 +01:00
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2020-07-20 12:25:57 +02:00
|
|
|
public static function MapAPIKey(): string
|
2019-12-09 11:47:17 +01:00
|
|
|
{
|
2019-12-11 03:30:39 +01:00
|
|
|
$type = self::config()->get('map_type');
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'mapbox':
|
|
|
|
$key = MapboxField::getAccessToken();
|
|
|
|
break;
|
|
|
|
case 'google-maps':
|
|
|
|
$cfg = Config::inst()->get(GoogleMapField::class, 'default_options');
|
|
|
|
$key = $cfg['api_key'];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$key = '';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $key;
|
2019-12-09 11:47:17 +01:00
|
|
|
}
|
|
|
|
}
|