From 3769c1260204eda5b5d9f94bfc15b4ea11a00f7d Mon Sep 17 00:00:00 2001 From: Tony Air Date: Wed, 25 May 2022 16:37:44 +0200 Subject: [PATCH] FIX: Minor fixtures --- src/Extensions/SiteConfigExtension.php | 39 ++++++++++++++++++++++---- src/Templates/DeferredRequirements.php | 6 ++-- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/Extensions/SiteConfigExtension.php b/src/Extensions/SiteConfigExtension.php index 389b172..3dbac3d 100755 --- a/src/Extensions/SiteConfigExtension.php +++ b/src/Extensions/SiteConfigExtension.php @@ -15,6 +15,7 @@ use SilverStripe\CMS\Model\SiteTree; use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TreeMultiselectField; use SilverStripe\Forms\DropdownField; +use Symbiote\Addressable\Addressable; //use BetterBrief\GoogleMapField; @@ -44,11 +45,11 @@ class SiteConfigExtension extends DataExtension 'Longitude' => 'Decimal(10, 8)', 'Latitude' => 'Decimal(11, 8)', 'MapZoom' => 'Int', - //'MapAPIKey' => 'Varchar(255)', 'Description' => 'Varchar(255)', 'Address' => 'Varchar(255)', 'Suburb' => 'Varchar(255)', 'State' => 'Varchar(255)', + 'Country' => 'Varchar(255)', 'ZipCode' => 'Varchar(6)', ]; @@ -98,12 +99,40 @@ class SiteConfigExtension extends DataExtension $mapTab = $fields->findOrMakeTab('Root.Maps'); $mapTab->setTitle('Address / Map'); - $fields->addFieldsToTab('Root.Maps', [ + + $addrFields =[ TextField::create('Address'), - TextField::create('Suburb', 'City'), - TextField::create('State'), TextField::create('ZipCode'), - ]); + TextField::create('Suburb', 'City'), + ]; + + if (\class_exists(Addressable::class)) { + $addr = \singleton(Addressable::class); + + + $stateLabel = _t('Addressable.STATE', 'State'); + $allowedStates = $addr->getAllowedStates(); + if (count($allowedStates) >= 1) { + // If allowed states are restricted, only allow those + $addrFields[] = DropdownField::create('State', $stateLabel, $allowedStates); + } elseif (!$allowedStates) { + // If no allowed states defined, allow the user to type anything + $addrFields[] = TextField::create('State', $stateLabel); + } + + // Get country field + $addrFields[] = DropdownField::create( + 'Country', + _t('Addressable.COUNTRY', 'Country'), + $addr->getAllowedCountries() + ); + } else { + $addrFields[] = TextField::create('State'); + $addrFields[] = TextField::create('Country'); + } + + + $fields->addFieldsToTab('Root.Maps', $addrFields); if (MapboxField::getAccessToken()) { $fields->addFieldsToTab('Root.Maps', [ diff --git a/src/Templates/DeferredRequirements.php b/src/Templates/DeferredRequirements.php index 1d70de2..869eb80 100755 --- a/src/Templates/DeferredRequirements.php +++ b/src/Templates/DeferredRequirements.php @@ -66,7 +66,7 @@ class DeferredRequirements implements TemplateGlobalProvider // Main libs if (!$config['nojquery']) { self::loadJS( - '//ajax.googleapis.com/ajax/libs/jquery/' + 'https://ajax.googleapis.com/ajax/libs/jquery/' .$config['jquery_version'].'/jquery.min.js' ); } @@ -140,9 +140,9 @@ class DeferredRequirements implements TemplateGlobalProvider if ($config['fontawesome_svg']) { Requirements::customScript('FontAwesomeConfig={searchPseudoElements:true}'); - self::loadJS('//use.fontawesome.com/releases/v'.$v.'/js/all.js'); + self::loadJS('https://use.fontawesome.com/releases/v'.$v.'/js/all.js'); } else { - self::loadCSS('//use.fontawesome.com/releases/v'.$v.'/css/all.css'); + self::loadCSS('https://use.fontawesome.com/releases/v'.$v.'/css/all.css'); } }