@@ -19,85 +19,85 @@ |
||
| 19 | 19 | class LocatorControllerTest extends FunctionalTest |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected static $fixture_file = 'locatorcontrollerfixture.yml'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var bool |
|
| 29 | - */ |
|
| 30 | - protected static $use_draft_site = true; |
|
| 31 | - |
|
| 32 | - protected function setUp() |
|
| 33 | - { |
|
| 34 | - parent::setUp(); |
|
| 35 | - |
|
| 36 | - Config::modify()->set(Locator::class, 'location_class', Location::class); |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * |
|
| 41 | - */ |
|
| 42 | - public function testIndex() |
|
| 43 | - { |
|
| 44 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 45 | - $controller = LocatorController::create($locator); |
|
| 46 | - $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * |
|
| 51 | - */ |
|
| 52 | - public function testXml() |
|
| 53 | - { |
|
| 54 | - /** @var Locator $locator */ |
|
| 55 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 56 | - $page = $this->get($locator->Link('xml')); |
|
| 57 | - |
|
| 58 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 59 | - $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 60 | - |
|
| 61 | - $dom = new \DOMDocument(); |
|
| 62 | - // true if it loads, false if it doesn't |
|
| 63 | - $valid = $dom->loadXML($page->getBody()); |
|
| 64 | - $this->assertTrue($valid); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * |
|
| 69 | - */ |
|
| 70 | - public function testJson() |
|
| 71 | - { |
|
| 72 | - /** @var Locator $locator */ |
|
| 73 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 74 | - $page = $this->get($locator->Link('json')); |
|
| 75 | - |
|
| 76 | - $this->assertEquals(200, $page->getStatusCode()); |
|
| 77 | - $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 78 | - |
|
| 79 | - $json = json_decode($page->getBody()); |
|
| 80 | - // if it is null its not valid |
|
| 81 | - $this->assertNotNull($json); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * |
|
| 86 | - */ |
|
| 87 | - public function testLocationSearch() |
|
| 88 | - { |
|
| 89 | - $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 90 | - $object = LocatorController::create($locator); |
|
| 91 | - $form = $object->LocationSearch(); |
|
| 92 | - $this->assertInstanceOf(Form::class, $form); |
|
| 93 | - |
|
| 94 | - $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 95 | - $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 96 | - $locator->Categories()->add($category); |
|
| 97 | - $locator->Categories()->add($category2); |
|
| 98 | - |
|
| 99 | - $form = $object->LocationSearch(); |
|
| 100 | - $fields = $form->Fields(); |
|
| 101 | - $this->assertInstanceOf(FieldList::class, $fields); |
|
| 102 | - } |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected static $fixture_file = 'locatorcontrollerfixture.yml'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var bool |
|
| 29 | + */ |
|
| 30 | + protected static $use_draft_site = true; |
|
| 31 | + |
|
| 32 | + protected function setUp() |
|
| 33 | + { |
|
| 34 | + parent::setUp(); |
|
| 35 | + |
|
| 36 | + Config::modify()->set(Locator::class, 'location_class', Location::class); |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * |
|
| 41 | + */ |
|
| 42 | + public function testIndex() |
|
| 43 | + { |
|
| 44 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 45 | + $controller = LocatorController::create($locator); |
|
| 46 | + $this->assertInstanceOf(ViewableData::class, $controller->index($controller->getRequest())); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * |
|
| 51 | + */ |
|
| 52 | + public function testXml() |
|
| 53 | + { |
|
| 54 | + /** @var Locator $locator */ |
|
| 55 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 56 | + $page = $this->get($locator->Link('xml')); |
|
| 57 | + |
|
| 58 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 59 | + $this->assertEquals('application/xml', $page->getHeader('content-type')); |
|
| 60 | + |
|
| 61 | + $dom = new \DOMDocument(); |
|
| 62 | + // true if it loads, false if it doesn't |
|
| 63 | + $valid = $dom->loadXML($page->getBody()); |
|
| 64 | + $this->assertTrue($valid); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * |
|
| 69 | + */ |
|
| 70 | + public function testJson() |
|
| 71 | + { |
|
| 72 | + /** @var Locator $locator */ |
|
| 73 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 74 | + $page = $this->get($locator->Link('json')); |
|
| 75 | + |
|
| 76 | + $this->assertEquals(200, $page->getStatusCode()); |
|
| 77 | + $this->assertEquals('application/json', $page->getHeader('content-type')); |
|
| 78 | + |
|
| 79 | + $json = json_decode($page->getBody()); |
|
| 80 | + // if it is null its not valid |
|
| 81 | + $this->assertNotNull($json); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * |
|
| 86 | + */ |
|
| 87 | + public function testLocationSearch() |
|
| 88 | + { |
|
| 89 | + $locator = $this->objFromFixture(Locator::class, 'locator1'); |
|
| 90 | + $object = LocatorController::create($locator); |
|
| 91 | + $form = $object->LocationSearch(); |
|
| 92 | + $this->assertInstanceOf(Form::class, $form); |
|
| 93 | + |
|
| 94 | + $category = $this->objFromFixture(LocationCategory::class, 'service'); |
|
| 95 | + $category2 = $this->objFromFixture(LocationCategory::class, 'manufacturing'); |
|
| 96 | + $locator->Categories()->add($category); |
|
| 97 | + $locator->Categories()->add($category2); |
|
| 98 | + |
|
| 99 | + $form = $object->LocationSearch(); |
|
| 100 | + $fields = $form->Fields(); |
|
| 101 | + $this->assertInstanceOf(FieldList::class, $fields); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -31,259 +31,259 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class LocationPage extends \Page implements PermissionProvider |
| 33 | 33 | { |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - private static $singular_name = 'Location'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var string |
|
| 41 | - */ |
|
| 42 | - private static $plural_name = 'Locations'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var array |
|
| 46 | - */ |
|
| 47 | - private static $db = [ |
|
| 48 | - 'Featured' => 'Boolean', |
|
| 49 | - 'Website' => 'Varchar(255)', |
|
| 50 | - 'Phone' => 'Varchar(40)', |
|
| 51 | - 'Email' => 'Varchar(255)', |
|
| 52 | - 'Fax' => 'Varchar(45)', |
|
| 53 | - 'Import_ID' => 'Int', |
|
| 54 | - 'LegacyObjectID' => 'Int', |
|
| 55 | - ]; |
|
| 56 | - |
|
| 57 | - private static $many_many = [ |
|
| 58 | - 'Categories' => LocationCategory::class, |
|
| 59 | - ]; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - private static $table_name = 'LocationPage'; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var array |
|
| 68 | - */ |
|
| 69 | - private static $casting = [ |
|
| 70 | - 'distance' => 'Decimal(9,3)', |
|
| 71 | - ]; |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - private static $default_sort = 'Title'; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * api access via Restful Server module |
|
| 80 | - * |
|
| 81 | - * @var bool |
|
| 82 | - */ |
|
| 83 | - private static $api_access = true; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * search fields for Model Admin |
|
| 87 | - * |
|
| 88 | - * @var array |
|
| 89 | - */ |
|
| 90 | - private static $searchable_fields = [ |
|
| 91 | - 'Title', |
|
| 92 | - 'Address', |
|
| 93 | - 'City', |
|
| 94 | - 'State', |
|
| 95 | - 'PostalCode', |
|
| 96 | - 'Country', |
|
| 97 | - 'Website', |
|
| 98 | - 'Phone', |
|
| 99 | - 'Email', |
|
| 100 | - 'Featured', |
|
| 101 | - ]; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * columns for grid field |
|
| 105 | - * |
|
| 106 | - * @var array |
|
| 107 | - */ |
|
| 108 | - private static $summary_fields = [ |
|
| 109 | - 'Title', |
|
| 110 | - 'Address', |
|
| 111 | - 'Address2', |
|
| 112 | - 'City', |
|
| 113 | - 'State', |
|
| 114 | - 'PostalCode', |
|
| 115 | - 'CountryCode', |
|
| 116 | - 'Phone' => 'Phone', |
|
| 117 | - 'Fax' => 'Fax', |
|
| 118 | - 'Email' => 'Email', |
|
| 119 | - 'Website' => 'Website', |
|
| 120 | - 'Featured', |
|
| 121 | - 'CategoryList', |
|
| 122 | - 'Lat', |
|
| 123 | - 'Lng', |
|
| 124 | - 'Import_ID', |
|
| 125 | - ]; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Coords status for $summary_fields |
|
| 129 | - * |
|
| 130 | - * @return string |
|
| 131 | - */ |
|
| 132 | - public function getCoords() |
|
| 133 | - { |
|
| 134 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function getCategoryList() |
|
| 141 | - { |
|
| 142 | - if ($this->Categories()->count()) { |
|
| 143 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @return bool|string |
|
| 151 | - */ |
|
| 152 | - public function getCountryCode() |
|
| 153 | - { |
|
| 154 | - if ($this->Country) { |
|
| 155 | - return strtoupper($this->Country); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * custom labels for fields |
|
| 163 | - * |
|
| 164 | - * @param bool $includerelations |
|
| 165 | - * @return array|string |
|
| 166 | - */ |
|
| 167 | - public function fieldLabels($includerelations = true) |
|
| 168 | - { |
|
| 169 | - $labels = parent::fieldLabels($includerelations); |
|
| 170 | - |
|
| 171 | - $labels['Title'] = 'Name'; |
|
| 172 | - $labels['Address2'] = 'Address 2'; |
|
| 173 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 174 | - $labels['Categories.Name'] = 'Categories'; |
|
| 175 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 176 | - |
|
| 177 | - return $labels; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * @return FieldList |
|
| 182 | - */ |
|
| 183 | - public function getCMSFields() |
|
| 184 | - { |
|
| 185 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 186 | - $fields->addFieldsToTab( |
|
| 187 | - 'Root.Main', |
|
| 188 | - [ |
|
| 189 | - CheckboxField::create('Featured') |
|
| 190 | - ->setTitle('Featured'), |
|
| 191 | - TextField::create('Website') |
|
| 192 | - ->setTitle('Website') |
|
| 193 | - ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 194 | - TextField::create('Phone') |
|
| 195 | - ->setTitle('Phone'), |
|
| 196 | - EmailField::create('Email') |
|
| 197 | - ->setTitle('Email'), |
|
| 198 | - TextField::create('Fax') |
|
| 199 | - ->setTitle('Fax'), |
|
| 200 | - ], |
|
| 201 | - 'Content' |
|
| 202 | - ); |
|
| 203 | - |
|
| 204 | - if ($this->exists()) { |
|
| 205 | - $fields->addFieldToTab( |
|
| 206 | - 'Root.Categories', |
|
| 207 | - GridField::create( |
|
| 208 | - 'Categories', |
|
| 209 | - 'Categories', |
|
| 210 | - $this->Categories(), |
|
| 211 | - $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 212 | - ) |
|
| 213 | - ); |
|
| 214 | - |
|
| 215 | - $catConfig->removeComponentsByType([ |
|
| 216 | - GridFieldAddExistingAutocompleter::class, |
|
| 217 | - ])->addComponents([ |
|
| 218 | - new GridFieldAddExistingSearchButton() |
|
| 219 | - ]); |
|
| 220 | - } |
|
| 221 | - }); |
|
| 222 | - |
|
| 223 | - return parent::getCMSFields(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * @param null $member |
|
| 228 | - * @param array $context |
|
| 229 | - * @return bool |
|
| 230 | - */ |
|
| 231 | - public function canView($member = null, $context = []) |
|
| 232 | - { |
|
| 233 | - return true; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - /** |
|
| 237 | - * @param null $member |
|
| 238 | - * @param array $context |
|
| 239 | - * @return bool|int |
|
| 240 | - */ |
|
| 241 | - public function canEdit($member = null, $context = []) |
|
| 242 | - { |
|
| 243 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - /** |
|
| 247 | - * @param null $member |
|
| 248 | - * @param array $context |
|
| 249 | - * @return bool|int |
|
| 250 | - */ |
|
| 251 | - public function canDelete($member = null, $context = []) |
|
| 252 | - { |
|
| 253 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @param null $member |
|
| 258 | - * @param array $context |
|
| 259 | - * @return bool|int |
|
| 260 | - */ |
|
| 261 | - public function canCreate($member = null, $context = []) |
|
| 262 | - { |
|
| 263 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * @return array |
|
| 268 | - */ |
|
| 269 | - public function providePermissions() |
|
| 270 | - { |
|
| 271 | - return [ |
|
| 272 | - 'Location_EDIT' => 'Edit a Location', |
|
| 273 | - 'Location_DELETE' => 'Delete a Location', |
|
| 274 | - 'Location_CREATE' => 'Create a Location', |
|
| 275 | - ]; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * @return string |
|
| 280 | - */ |
|
| 281 | - public function getWebsiteURL() |
|
| 282 | - { |
|
| 283 | - $url = $this->Website; |
|
| 284 | - |
|
| 285 | - $this->extend('updateWebsiteURL', $url); |
|
| 286 | - |
|
| 287 | - return $url; |
|
| 288 | - } |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + private static $singular_name = 'Location'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var string |
|
| 41 | + */ |
|
| 42 | + private static $plural_name = 'Locations'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var array |
|
| 46 | + */ |
|
| 47 | + private static $db = [ |
|
| 48 | + 'Featured' => 'Boolean', |
|
| 49 | + 'Website' => 'Varchar(255)', |
|
| 50 | + 'Phone' => 'Varchar(40)', |
|
| 51 | + 'Email' => 'Varchar(255)', |
|
| 52 | + 'Fax' => 'Varchar(45)', |
|
| 53 | + 'Import_ID' => 'Int', |
|
| 54 | + 'LegacyObjectID' => 'Int', |
|
| 55 | + ]; |
|
| 56 | + |
|
| 57 | + private static $many_many = [ |
|
| 58 | + 'Categories' => LocationCategory::class, |
|
| 59 | + ]; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + private static $table_name = 'LocationPage'; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var array |
|
| 68 | + */ |
|
| 69 | + private static $casting = [ |
|
| 70 | + 'distance' => 'Decimal(9,3)', |
|
| 71 | + ]; |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + private static $default_sort = 'Title'; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * api access via Restful Server module |
|
| 80 | + * |
|
| 81 | + * @var bool |
|
| 82 | + */ |
|
| 83 | + private static $api_access = true; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * search fields for Model Admin |
|
| 87 | + * |
|
| 88 | + * @var array |
|
| 89 | + */ |
|
| 90 | + private static $searchable_fields = [ |
|
| 91 | + 'Title', |
|
| 92 | + 'Address', |
|
| 93 | + 'City', |
|
| 94 | + 'State', |
|
| 95 | + 'PostalCode', |
|
| 96 | + 'Country', |
|
| 97 | + 'Website', |
|
| 98 | + 'Phone', |
|
| 99 | + 'Email', |
|
| 100 | + 'Featured', |
|
| 101 | + ]; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * columns for grid field |
|
| 105 | + * |
|
| 106 | + * @var array |
|
| 107 | + */ |
|
| 108 | + private static $summary_fields = [ |
|
| 109 | + 'Title', |
|
| 110 | + 'Address', |
|
| 111 | + 'Address2', |
|
| 112 | + 'City', |
|
| 113 | + 'State', |
|
| 114 | + 'PostalCode', |
|
| 115 | + 'CountryCode', |
|
| 116 | + 'Phone' => 'Phone', |
|
| 117 | + 'Fax' => 'Fax', |
|
| 118 | + 'Email' => 'Email', |
|
| 119 | + 'Website' => 'Website', |
|
| 120 | + 'Featured', |
|
| 121 | + 'CategoryList', |
|
| 122 | + 'Lat', |
|
| 123 | + 'Lng', |
|
| 124 | + 'Import_ID', |
|
| 125 | + ]; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Coords status for $summary_fields |
|
| 129 | + * |
|
| 130 | + * @return string |
|
| 131 | + */ |
|
| 132 | + public function getCoords() |
|
| 133 | + { |
|
| 134 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function getCategoryList() |
|
| 141 | + { |
|
| 142 | + if ($this->Categories()->count()) { |
|
| 143 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @return bool|string |
|
| 151 | + */ |
|
| 152 | + public function getCountryCode() |
|
| 153 | + { |
|
| 154 | + if ($this->Country) { |
|
| 155 | + return strtoupper($this->Country); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * custom labels for fields |
|
| 163 | + * |
|
| 164 | + * @param bool $includerelations |
|
| 165 | + * @return array|string |
|
| 166 | + */ |
|
| 167 | + public function fieldLabels($includerelations = true) |
|
| 168 | + { |
|
| 169 | + $labels = parent::fieldLabels($includerelations); |
|
| 170 | + |
|
| 171 | + $labels['Title'] = 'Name'; |
|
| 172 | + $labels['Address2'] = 'Address 2'; |
|
| 173 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 174 | + $labels['Categories.Name'] = 'Categories'; |
|
| 175 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 176 | + |
|
| 177 | + return $labels; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * @return FieldList |
|
| 182 | + */ |
|
| 183 | + public function getCMSFields() |
|
| 184 | + { |
|
| 185 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 186 | + $fields->addFieldsToTab( |
|
| 187 | + 'Root.Main', |
|
| 188 | + [ |
|
| 189 | + CheckboxField::create('Featured') |
|
| 190 | + ->setTitle('Featured'), |
|
| 191 | + TextField::create('Website') |
|
| 192 | + ->setTitle('Website') |
|
| 193 | + ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 194 | + TextField::create('Phone') |
|
| 195 | + ->setTitle('Phone'), |
|
| 196 | + EmailField::create('Email') |
|
| 197 | + ->setTitle('Email'), |
|
| 198 | + TextField::create('Fax') |
|
| 199 | + ->setTitle('Fax'), |
|
| 200 | + ], |
|
| 201 | + 'Content' |
|
| 202 | + ); |
|
| 203 | + |
|
| 204 | + if ($this->exists()) { |
|
| 205 | + $fields->addFieldToTab( |
|
| 206 | + 'Root.Categories', |
|
| 207 | + GridField::create( |
|
| 208 | + 'Categories', |
|
| 209 | + 'Categories', |
|
| 210 | + $this->Categories(), |
|
| 211 | + $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 212 | + ) |
|
| 213 | + ); |
|
| 214 | + |
|
| 215 | + $catConfig->removeComponentsByType([ |
|
| 216 | + GridFieldAddExistingAutocompleter::class, |
|
| 217 | + ])->addComponents([ |
|
| 218 | + new GridFieldAddExistingSearchButton() |
|
| 219 | + ]); |
|
| 220 | + } |
|
| 221 | + }); |
|
| 222 | + |
|
| 223 | + return parent::getCMSFields(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * @param null $member |
|
| 228 | + * @param array $context |
|
| 229 | + * @return bool |
|
| 230 | + */ |
|
| 231 | + public function canView($member = null, $context = []) |
|
| 232 | + { |
|
| 233 | + return true; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + /** |
|
| 237 | + * @param null $member |
|
| 238 | + * @param array $context |
|
| 239 | + * @return bool|int |
|
| 240 | + */ |
|
| 241 | + public function canEdit($member = null, $context = []) |
|
| 242 | + { |
|
| 243 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + /** |
|
| 247 | + * @param null $member |
|
| 248 | + * @param array $context |
|
| 249 | + * @return bool|int |
|
| 250 | + */ |
|
| 251 | + public function canDelete($member = null, $context = []) |
|
| 252 | + { |
|
| 253 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @param null $member |
|
| 258 | + * @param array $context |
|
| 259 | + * @return bool|int |
|
| 260 | + */ |
|
| 261 | + public function canCreate($member = null, $context = []) |
|
| 262 | + { |
|
| 263 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * @return array |
|
| 268 | + */ |
|
| 269 | + public function providePermissions() |
|
| 270 | + { |
|
| 271 | + return [ |
|
| 272 | + 'Location_EDIT' => 'Edit a Location', |
|
| 273 | + 'Location_DELETE' => 'Delete a Location', |
|
| 274 | + 'Location_CREATE' => 'Create a Location', |
|
| 275 | + ]; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * @return string |
|
| 280 | + */ |
|
| 281 | + public function getWebsiteURL() |
|
| 282 | + { |
|
| 283 | + $url = $this->Website; |
|
| 284 | + |
|
| 285 | + $this->extend('updateWebsiteURL', $url); |
|
| 286 | + |
|
| 287 | + return $url; |
|
| 288 | + } |
|
| 289 | 289 | } |