diff --git a/src/MarkerExtension.php b/src/MarkerExtension.php index 663971c..06b8c1f 100644 --- a/src/MarkerExtension.php +++ b/src/MarkerExtension.php @@ -6,23 +6,36 @@ namespace A2nt\SilverStripeMapboxField; use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\FieldList; use Symbiote\Addressable\Geocodable; +use Symbiote\Addressable\Addressable; class MarkerExtension extends Geocodable { private static $icon = ''; private $curr_icon = null; + private static $db = [ + 'DirectionsByAddress' => 'Boolean(0)', + ]; + public function updateCMSFields(FieldList $fields) { parent::updateCMSFields($fields); $record = $this->getOwner(); - $fields->removeByName(['LatLngOverride', 'Lng','Lat']); + $fields->removeByName(['DirectionsByAddress', 'LatLngOverride', 'Lng', 'Lat']); + + + if ($this->owner->hasExtension(Addressable::class)) { + $fields->addFieldsToTab('Root.Map', [ + CheckboxField::create('DirectionsByAddress', 'Directions by address') + ->setDescription('Check this box to link directions by address') + ]); + } $fields->addFieldsToTab('Root.Map', [ CheckboxField::create('LatLngOverride', 'Override Latitude and Longitude?') - ->setDescription('Check this box and save to be able to edit the latitude and longitude manually.'), + ->setDescription('Check this box and save to be able to set the latitude and longitude manually.'), MapboxField::create('Map', 'Choose a location', 'Lat', 'Lng'), ]); } @@ -31,7 +44,15 @@ class MarkerExtension extends Geocodable { $obj = $this->owner; return 'https://www.google.com/maps/dir/Current+Location/' - .$obj->getField('Lat').',' .$obj->getField('Lng'); + .( + $obj->getField('DirectionsByAddress') + ? urlencode( + $obj->getField('Address').', '.$obj->getField('Suburb') + .', '.$obj->getField('State').' '.$obj->getField('Postcode') + .', '.$obj->getField('Country') + ) + : $obj->getField('Lat').',' .$obj->getField('Lng') + ); } public function getIcon()