diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19f7e63..7a973e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,6 +8,4 @@ on: jobs: ci: name: CI - uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 - with: - phpcoverage: true + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 \ No newline at end of file diff --git a/_config/config.yml b/_config/config.yml index e69de29..2f8912d 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -0,0 +1,3 @@ +Dynamic\Locations\Model\LocationCategory: + extensions: + - Dynamic\Elements\Locaitons\Extension\LocationCategoryDataExtension \ No newline at end of file diff --git a/composer.json b/composer.json index e74ea30..079838f 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,9 @@ "CMS" ], "require": { - "dnadesign/silverstripe-elemental": "^5.0" + "dnadesign/silverstripe-elemental": "^5.0", + "dynamic/silverstripe-locations": "^1.0", + "silverstripe/tagfield": "^3.0" }, "require-dev": { "silverstripe/recipe-testing": "^3" diff --git a/src/Element/ElementLocations.php b/src/Element/ElementLocations.php new file mode 100644 index 0000000..58d0bf7 --- /dev/null +++ b/src/Element/ElementLocations.php @@ -0,0 +1,110 @@ + LocationCategory::class, + ]; + + /** + * @return FieldList + */ + public function getCMSFields(): FieldList + { + $this->beforeUpdateCMSFields(function (FieldList $fields) { + + $fields->removeByName('Categories'); + + $fields->addFieldToTab( + 'Root.Main', + TagField::create( + 'Categories', + 'Categories', + LocationCategory::get(), + $this->Categories() + ) + ); + }); + + return parent::getCMSFields(); + } + + /** + * return ArrayList + */ + public function getLocationsList() + { + $locations = ArrayList::create(); + + if ($this->Categories()->count()) { + $locations = Location::get()->filter('Categories.ID', $this->Categories()->column()); + } else { + $locations = Location::get(); + } + + $this->extend('updateGetLocationsList', $locations); + + return $locations; + } + + /** + * @return string + */ + public function getSummary(): string + { + $count = $this->getLocationsList()->count(); + $label = _t( + Location::class . '.PLURALS', + '1 Location|{count} Locations', + [ 'count' => $count ] + ); + return DBField::create_field('HTMLText', $label)->Summary(20); + } + + /** + * @return string + */ + public function getType(): string + { + return _t(__CLASS__ . '.BlockType', 'Locations'); + } +} diff --git a/src/Extension/LocationCategoryDataExtension.php b/src/Extension/LocationCategoryDataExtension.php new file mode 100644 index 0000000..6a5f1da --- /dev/null +++ b/src/Extension/LocationCategoryDataExtension.php @@ -0,0 +1,23 @@ + ElementLocations::class, + ]; +} diff --git a/templates/Dynamic/Elements/Locations/Elements/ElementLocations.ss b/templates/Dynamic/Elements/Locations/Elements/ElementLocations.ss new file mode 100644 index 0000000..dbd042d --- /dev/null +++ b/templates/Dynamic/Elements/Locations/Elements/ElementLocations.ss @@ -0,0 +1,2 @@ +<% if $Title && $ShowTitle %>