1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverCommerce\GeoZones\Extensions; |
4
|
|
|
|
5
|
|
|
use SilverCommerce\GeoZones\Helpers\GeoZonesHelper; |
6
|
|
|
use SilverCommerce\GeoZones\Model\Region; |
7
|
|
|
use SilverStripe\Forms\FieldList; |
8
|
|
|
use SilverStripe\ORM\DataExtension; |
9
|
|
|
use SilverCommerce\GeoZones\Model\Zone; |
10
|
|
|
use SilverStripe\Forms\GridField\GridField; |
11
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_Base; |
12
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
13
|
|
|
use SilverStripe\Forms\GridField\GridFieldDataColumns; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Add postage areas to config |
17
|
|
|
*/ |
18
|
|
|
class SiteConfigExtension extends DataExtension |
19
|
|
|
{ |
20
|
|
|
private static $has_many = [ |
|
|
|
|
21
|
|
|
'GeoZones' => Zone::class |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
public function updateCMSFields(FieldList $fields) |
25
|
|
|
{ |
26
|
|
|
$helper = GeoZonesHelper::create(); |
27
|
|
|
|
28
|
|
|
$region_config = GridFieldConfig_Base::create(); |
29
|
|
|
$region_config |
30
|
|
|
->getComponentByType(GridFieldDataColumns::class) |
31
|
|
|
->setDisplayFields([ |
32
|
|
|
"Name" => _t("SilverCommerce\GeoZones.RegionName", "Name"), |
33
|
|
|
"Type" => _t("SilverCommerce\GeoZones.RegionType", "Type"), |
34
|
|
|
"RegionCode" => _t("SilverCommerce\GeoZones.RegionCode", "Region Code"), |
35
|
|
|
"CountryCode" => _t("SilverCommerce\GeoZones.CountryCode", "Country Code") |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
$fields->addFieldsToTab( |
39
|
|
|
"Root.GeoZones", |
40
|
|
|
[ |
41
|
|
|
// Generate a list of zones for the current site |
42
|
|
|
GridField::create( |
43
|
|
|
'GeoZones', |
44
|
|
|
_t("SilverCommerce\GeoZones.Zones", "Zones"), |
45
|
|
|
$this->owner->GeoZones() |
46
|
|
|
)->setConfig(GridFieldConfig_RelationEditor::create()), |
47
|
|
|
|
48
|
|
|
// Show all current regions in the system |
49
|
|
|
GridField::create( |
50
|
|
|
'GeoZoneRegions', |
51
|
|
|
_t("SilverCommerce\GeoZones.RegionList", "All regions available (more can be added via YML config)"), |
52
|
|
|
$helper->getRegionsAsObjects() |
53
|
|
|
)->setConfig($region_config) |
54
|
|
|
->setModelClass(Region::class) |
55
|
|
|
] |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
} |