diff --git a/README.md b/README.md index 4b53da0..519201d 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ a simple base dataobject to use with elements [![CI](https://github.com/dynamic/silverstripe-elemental-baseobject/actions/workflows/ci.yml/badge.svg)](https://github.com/dynamic/silverstripe-elemental-baseobject/actions/workflows/ci.yml) -[![codecov](https://codecov.io/gh/dynamic/silverstripe-elemental-baseobject/branch/master/graph/badge.svg)](https://codecov.io/gh/dynamic/silverstripe-elemental-baseobject) [![Latest Stable Version](https://poser.pugx.org/dynamic/silverstripe-elemental-baseobject/v/stable)](https://packagist.org/packages/dynamic/silverstripe-elemental-baseobject) [![Total Downloads](https://poser.pugx.org/dynamic/silverstripe-elemental-baseobject/downloads)](https://packagist.org/packages/dynamic/silverstripe-elemental-baseobject) @@ -12,8 +11,10 @@ a simple base dataobject to use with elements ## Requirements -* dnadesign/silverstripe-elemental: ^5.0 -* silverstripe/linkfield: ^4.0 +* SilverStripe: ^6.0 +* dnadesign/silverstripe-elemental: ^6.0 +* silverstripe/linkfield: ^5.0 +* PHP: ^8.1 ## Installation @@ -23,31 +24,64 @@ a simple base dataobject to use with elements See [License](LICENSE.md) -## Upgrading from version 2 +## Usage -BaseObject drops `sheadawson/silverstripe-linkable` usage in favor of `gorriecoe/silverstripe-linkfield`. To avoid data loss, install the `dynamic/silverstripe-link-migrator` module as follows: +`BaseElementObject` is a versioned DataObject that provides a reusable foundation for managing collections of related content within Elemental blocks. It's designed to be extended or used as a `has_many` relationship in custom Element classes. -```markdown -composer require dynamic/silverstripe-link-migrator -``` +### Features + +The base object includes: + +- **Title** - Text field with optional display toggle (using `TextCheckboxGroupField`) +- **Content** - HTML text area for rich content +- **Image** - Image upload with automatic organization into `Uploads/Elements/Objects` +- **Link** - Configurable call-to-action using SilverStripe LinkField +- **Versioning** - Full draft/publish workflow with GridField extensions +- **Permissions** - Inherits permissions from the current page context + +### Common Usage Pattern + +Typically used as a `has_many` relationship in Elemental blocks: -Then, run the task "Linkable to SilverStripe Link Migration" via `/dev/tasks`, or cli via: -```markdown -vendor/bin/sake dev/tasks/LinkableMigrationTask +```php +use Dynamic\BaseObject\Model\BaseElementObject; +use DNADesign\Elemental\Models\BaseElement; + +class ElementAccordion extends BaseElement +{ + private static $has_many = [ + 'Items' => BaseElementObject::class, + ]; +} ``` -This will populate all of the new Link fields with data from the old class. +### Extending BaseElementObject -## Usage +For custom functionality, extend the class: + +```php +use Dynamic\BaseObject\Model\BaseElementObject; + +class PromoObject extends BaseElementObject +{ + private static $db = [ + 'Subtitle' => 'Varchar(255)', + ]; + + private static $table_name = 'PromoObject'; +} +``` + +### Used By -A base DataObject used in the following Elemental content blocks: +This module serves as a dependency for several Dynamic Elemental modules: -* [Accordion](https://github.com/dynamic/silverstripe-elemental-accordion) -* [Features](https://github.com/dynamic/silverstripe-elemental-features) -* [Gallery](https://github.com/dynamic/silverstripe-elemental-gallery) -* [Promos](https://github.com/dynamic/silverstripe-elemental-promos) -* [Sponsors](https://github.com/dynamic/silverstripe-elemental-sponsors) -* [Timeline](https://github.com/dynamic/silverstripe-elemental-timeline) +* [Accordion](https://github.com/dynamic/silverstripe-elemental-accordion) - Collapsible content panels +* [Features](https://github.com/dynamic/silverstripe-elemental-features) - Icon-based feature highlights +* [Gallery](https://github.com/dynamic/silverstripe-elemental-gallery) - Image galleries with captions +* [Promos](https://github.com/dynamic/silverstripe-elemental-promos) - Promotional content blocks +* [Sponsors](https://github.com/dynamic/silverstripe-elemental-sponsors) - Sponsor/partner logos +* [Timeline](https://github.com/dynamic/silverstripe-elemental-timeline) - Event timelines ## Getting more elements diff --git a/composer.json b/composer.json index a284a25..2f55aa1 100644 --- a/composer.json +++ b/composer.json @@ -17,14 +17,16 @@ } ], "require": { - "dnadesign/silverstripe-elemental": "^5", - "silvershop/silverstripe-hasonefield": "^4", - "silverstripe/linkfield": "^4.0", - "unclecheese/display-logic": "^3" + "dnadesign/silverstripe-elemental": "^6.0", + "silvershop/silverstripe-hasonefield": "^5.0", + "silverstripe/linkfield": "^5.0", + "unclecheese/display-logic": "^4.0" }, "require-dev": { - "silverstripe/recipe-testing": "^3", - "silverstripe/frameworktest": "^1" + "cambis/silverstan": "^2.1", + "phpstan/extension-installer": "^1.4", + "silverstripe/recipe-testing": "^4.0", + "squizlabs/php_codesniffer": "^3.7" }, "minimum-stability": "dev", "prefer-stable": true, @@ -37,8 +39,8 @@ "config": { "allow-plugins": { "composer/installers": true, - "silverstripe/vendor-plugin": true, - "silverstripe/recipe-plugin": true + "silverstripe/recipe-plugin": true, + "silverstripe/vendor-plugin": true }, "process-timeout": 600 } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..ad43fef --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 4 + treatPhpDocTypesAsCertain: false + paths: + - src + ignoreErrors: + # SilverStripe specific ignores can be added here if needed diff --git a/src/Model/BaseElementObject.php b/src/Model/BaseElementObject.php index bf3b0e5..b0e53c4 100644 --- a/src/Model/BaseElementObject.php +++ b/src/Model/BaseElementObject.php @@ -146,10 +146,12 @@ public function getCMSFields() $fields->insertBefore('Content', $fields->dataFieldByName('ElementLink')); $image = $fields->dataFieldByName('Image') - ->setDescription(_t(__CLASS__.'.ImageDescription', 'optional. Display an image.')) - ->setFolderName('Uploads/Elements/Objects'); + ->setDescription(_t(__CLASS__.'.ImageDescription', 'optional. Display an image.')); + // @phpstan-ignore-next-line + $image->setFolderName('Uploads/Elements/Objects'); $fields->insertBefore('Content', $image); + // @phpstan-ignore-next-line $fields->dataFieldByName('Content') ->setRows(8); }); @@ -227,6 +229,7 @@ public function canDelete($member = null) } if ($page = $this->getPage()) { + // @phpstan-ignore-next-line return $page->canArchive($member); }