Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE TagField for category management #9

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 18 additions & 1 deletion src/Model/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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'),
]
);
Expand Down
Loading