Extends the SilverStripe v4 ModelAdmin
to support filtering of versioned data objects.
Traditionally, versioning in SilverStripe has been the sole domain of
SiteTree
objects within the CMS, such as the ubiquitous Page
class.
With the advent of SilverStripe v4, versioning is now used in
other areas of the CMS, such as assets.
You can add versioning to your own model classes by using the
Versioned
extension. ModelAdmin
supports
versioned data objects out of the box, however filtering these objects
by their status is a bit trickier.
Enter silverware/model-filters
. After installation of this module,
your versioned data objects will have a status dropdown field added to
the filter form that appears within ModelAdmin
, allowing the user
to filter records by their versioning status:
You can also add StatusBadges
to your $summary_fields
to show
the versioning status within your model admin grid field:
Installation is via Composer:
$ composer require silverware/model-filters
Once installed, Versioned
data objects within ModelAdmin
will
be automatically detected and a status field will appear within
the filter form for each object.
In order to show status badges within the grid field for your
versioned objects, simply add StatusBadges
to your $summary_fields
static,
for example:
private static $summary_fields = [
...
'StatusBadges',
...
];
By default, the status dropdown field will be added to the end of
your search filter fields for each versioned object. To control
where the field appears, add one of the following methods to
your ModelAdmin
subclass:
public function getStatusFieldBefore()
{
return 'NameOfField'; // will appear before this field
}
public function getStatusFieldAfter()
{
return 'NameOfField'; // will appear after this field
}
You could also detect the current model class via $this->modelClass
and answer a
different field name, if required:
public function getStatusFieldAfter()
{
switch ($this->modelClass) {
case FirstModel::class:
return 'AfterThisField';
case SecondModel::class:
return 'AfterAnotherField';
}
}
By default, the title of the status dropdown field is "Record status". The title
is obtained by calling getStatusFieldTitle()
on the ModelAdmin
subclass. The method
added via the extension supports i18n
via the usual SilverStripe
conventions, however you can also override the method in your
ModelAdmin
subclass to answer a different field title:
public function getStatusFieldTitle()
{
return 'New field title';
}
Please use the GitHub issue tracker for bug reports and feature requests.
Your contributions are gladly welcomed to help make this project better. Please see contributing for more information.
Colin Tucker | Praxis Interactive |
BSD-3-Clause © Praxis Interactive