Skip to content
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
74 changes: 54 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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

Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 4
treatPhpDocTypesAsCertain: false
paths:
- src
ignoreErrors:
# SilverStripe specific ignores can be added here if needed
7 changes: 5 additions & 2 deletions src/Model/BaseElementObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -227,6 +229,7 @@ public function canDelete($member = null)
}

if ($page = $this->getPage()) {
// @phpstan-ignore-next-line
return $page->canArchive($member);
}

Expand Down