From 3c5e3efc752fded29fee456093bfec7b2b78f4fa Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Thu, 5 Sep 2024 14:35:05 -0500 Subject: [PATCH] FEATURE initial modeling (#3) --- composer.json | 31 +++++---- src/Admin/LocationsAdmin.php | 35 ++++++++++ src/Model/Location.php | 95 ++++++++++++++++++++++++++++ src/Model/LocationCategory.php | 54 ++++++++++++++++ tests/Model/LocationCategoryTest.php | 25 ++++++++ tests/Model/LocationTest.php | 25 ++++++++ tests/Model/location-category.yml | 3 + tests/Model/location.yml | 3 + 8 files changed, 258 insertions(+), 13 deletions(-) create mode 100644 src/Admin/LocationsAdmin.php create mode 100644 src/Model/Location.php create mode 100644 src/Model/LocationCategory.php create mode 100644 tests/Model/LocationCategoryTest.php create mode 100644 tests/Model/LocationTest.php create mode 100644 tests/Model/location-category.yml create mode 100644 tests/Model/location.yml diff --git a/composer.json b/composer.json index 14b991d..3e608ac 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,30 @@ { "name": "dynamic/silverstripe-locations", "description": "A locations module for silverstripe.", + "license": "BSD-3-Clause", "type": "silverstripe-vendormodule", "keywords": [ "silverstripe", "CMS", "locations" ], - "license": "BSD-3-Clause", + "authors": [ + { + "name": "Dynamic", + "email": "dev@dynamicagency.com", + "homepage": "https://www.dynamicagency.com" + } + ], "require": { - "silverstripe/admin": "^2.0" + "silverstripe/recipe-cms": "^5.0", + "silverstripe/linkfield": "^4.0" }, "require-dev": { - "phpunit/phpunit": "^9.6", - "silverstripe/frameworktest": "^1", - "squizlabs/php_codesniffer": "^3.7", - "silverstripe/standards": "^1", - "phpstan/extension-installer": "^1.3" + "dnadesign/silverstripe-elemental": "^5", + "silverstripe/recipe-testing": "^3" }, + "minimum-stability": "dev", + "prefer-stable": true, "autoload": { "psr-4": { "Dynamic\\Locations\\": "src/", @@ -25,10 +32,8 @@ } }, "extra": { - "expose": [ - "client/dist" - ] - }, - "minimum-stability": "dev", - "prefer-stable": true + "branch-alias": { + "dev-master": "1.x-dev" + } + } } diff --git a/src/Admin/LocationsAdmin.php b/src/Admin/LocationsAdmin.php new file mode 100644 index 0000000..03314e3 --- /dev/null +++ b/src/Admin/LocationsAdmin.php @@ -0,0 +1,35 @@ + 'Varchar(255)', + 'Content' => 'HTMLText', + ]; + + /** + * @var array + * @config + */ + private static array $has_many = [ + 'Links' => Link::class . '.Owner', + ]; + + /** + * @var array + * @config + */ + private static array $many_many = [ + 'Categories' => LocationCategory::class, + ]; + + /** + * @var array + * @config + */ + private static array $owns = [ + 'Links', + ]; + + /** + * @return FieldList + */ + public function getCMSFields(): FieldList + { + $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..f657285 --- /dev/null +++ b/src/Model/LocationCategory.php @@ -0,0 +1,54 @@ + 'Varchar(255)', + ]; + + /** + * @var array + * @config + */ + private static array $belongs_many_many = [ + 'Locations' => Location::class, + ]; +} diff --git a/tests/Model/LocationCategoryTest.php b/tests/Model/LocationCategoryTest.php new file mode 100644 index 0000000..c10c926 --- /dev/null +++ b/tests/Model/LocationCategoryTest.php @@ -0,0 +1,25 @@ +objFromFixture(LocationCategory::class, 'one'); + $fields = $object->getCMSFields(); + $this->assertInstanceOf(FieldList::class, $fields); + } +} diff --git a/tests/Model/LocationTest.php b/tests/Model/LocationTest.php new file mode 100644 index 0000000..14aa947 --- /dev/null +++ b/tests/Model/LocationTest.php @@ -0,0 +1,25 @@ +objFromFixture(Location::class, 'one'); + $fields = $object->getCMSFields(); + $this->assertInstanceOf(FieldList::class, $fields); + } +} diff --git a/tests/Model/location-category.yml b/tests/Model/location-category.yml new file mode 100644 index 0000000..17afa47 --- /dev/null +++ b/tests/Model/location-category.yml @@ -0,0 +1,3 @@ +Dynamic\Locations\Model\LocationCategory: + one: + Title: "Location Category One" diff --git a/tests/Model/location.yml b/tests/Model/location.yml new file mode 100644 index 0000000..654a02c --- /dev/null +++ b/tests/Model/location.yml @@ -0,0 +1,3 @@ +Dynamic\Locations\Model\Location: + one: + Title: "Location One"