From 82db9ad0934562e1102085ac9a21983423369d1d Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Wed, 4 Sep 2024 12:34:21 -0500 Subject: [PATCH] FEATURE initial modeling --- composer.json | 13 ++--- src/Admin/LocationsAdmin.php | 32 ++++++++++++ src/Model/Location.php | 94 ++++++++++++++++++++++++++++++++++ src/Model/LocationCategory.php | 48 +++++++++++++++++ 4 files changed, 181 insertions(+), 6 deletions(-) create mode 100644 src/Admin/LocationsAdmin.php create mode 100644 src/Model/Location.php create mode 100644 src/Model/LocationCategory.php diff --git a/composer.json b/composer.json index a6eb33e..ffd7bcb 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,32 @@ { "name": "dynamic/silverstripe-elemental-locations", "description": "A locations block for Silverstripe. Display one or more locations on a map.", + "license": "BSD-3-Clause", "type": "silverstripe-vendormodule", "keywords": [ "silverstripe", "CMS" ], - "license": "BSD-3-Clause", "require": { - "dnadesign/silverstripe-elemental": "^4.8", + "dnadesign/silverstripe-elemental": "^5", + "silverstripe/linkfield": "^4.0", "symbiote/silverstripe-addressable": "^5.0" }, "require-dev": { "silverstripe/recipe-testing": "^2", "squizlabs/php_codesniffer": "^3.0" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Dynamic\\Elements\\Locations\\": "src/", - "Dynamic\\Elements\\Blog\\Locations\\": "tests/" + "Dynamic\\Elements\\\\Locations\\Test\\": "tests/" } }, "extra": { "branch-alias": { "dev-master": "1.x-dev" } - }, - "minimum-stability": "dev", - "prefer-stable": true + } } diff --git a/src/Admin/LocationsAdmin.php b/src/Admin/LocationsAdmin.php new file mode 100644 index 0000000..e1eaecf --- /dev/null +++ b/src/Admin/LocationsAdmin.php @@ -0,0 +1,32 @@ + 'Varchar(255)', + 'Phone' => 'Varchar(40)', + 'Email' => 'Varchar(255)', + 'Fax' => 'Varchar(45)', + ]; + + /** + * @var array + */ + private static $has_many = [ + 'Links' => Link::class, + ]; + + /** + * @var array + */ + private static $many_many = [ + 'Categories' => LocationCategory::class, + ]; + + /** + * @var array + */ + private static $owns = [ + 'Links', + ]; + + /** + * @var array + */ + public function getCMSFields() + { + $this->beforeUpdateCMSFields(function (FieldList $fields) { + $fields->removeByName(['Links']); + + $fields->addFieldsToTab( + 'Root.Main', + [ + MultiLinkField::create('Links'), + ] + ); + }); + + return parent::getCMSFields(); + } +} diff --git a/src/Model/LocationCategory.php b/src/Model/LocationCategory.php new file mode 100644 index 0000000..6909031 --- /dev/null +++ b/src/Model/LocationCategory.php @@ -0,0 +1,48 @@ + 'Varchar(255)', + ]; + + /** + * @var array + */ + private static $belongs_many_many = [ + 'Locations' => Location::class, + ]; +}