From 21389d475af63d76d0f53261f0f2484e4ed91f55 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Thu, 12 Sep 2024 11:48:01 -0500 Subject: [PATCH] FEATURE TagField for category management --- composer.json | 3 ++- src/Model/Location.php | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 5c68b73..43f62af 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "require": { "dynamic/silverstripe-geocoder": "^3.0", "silverstripe/linkfield": "^4.0", - "silverstripe/recipe-cms": "^5.0" + "silverstripe/recipe-cms": "^5.0", + "silverstripe/tagfield": "^3.0" }, "require-dev": { "dnadesign/silverstripe-elemental": "^5", diff --git a/src/Model/Location.php b/src/Model/Location.php index 47d3b22..90c2eb8 100644 --- a/src/Model/Location.php +++ b/src/Model/Location.php @@ -7,15 +7,28 @@ use SilverStripe\Forms\FieldList; use SilverStripe\LinkField\Models\Link; use SilverStripe\LinkField\Form\MultiLinkField; +use SilverStripe\TagField\TagField; use SilverStripe\Versioned\Versioned; /** * Class \Dynamic\Elements\Locations\Model\Location * + * @property string $Address + * @property string $Address2 + * @property string $City + * @property string $State + * @property string $PostalCode + * @property string $Country + * @property bool $LatLngOverride + * @property float $Lat + * @property float $Lng + * @property int $Version * @property string $Title * @property string $Content * @method DataList|Link[] Links() * @method ManyManyList|LocationCategory[] Categories() + * @mixin Versioned + * @mixin AddressDataExtension */ class Location extends DataObject { @@ -143,11 +156,15 @@ public function fieldLabels($includerelations = true) public function getCMSFields(): FieldList { $this->beforeUpdateCMSFields(function (FieldList $fields) { - $fields->removeByName(['Links']); + $fields->removeByName([ + 'Links', + 'Categories', + ]); $fields->addFieldsToTab( 'Root.Main', [ + TagField::create('Categories', 'Categories', LocationCategory::get(), $this->Categories()), MultiLinkField::create('Links'), ] );