silverware/model-filters

SilverWare Model Filters Module.

Installs: 359

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 2

Open Issues: 0

Type:silverstripe-vendormodule

1.1.0 2018-06-12 06:59 UTC

This package is not auto-updated.

Last update: 2024-10-25 10:11:46 UTC


README

Latest Stable Version Latest Unstable Version License

Extends the SilverStripe v4 ModelAdmin to support filtering of versioned data objects.

Contents

Background

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:

Record Status Filter

You can also add StatusBadges to your $summary_fields to show the versioning status within your model admin grid field:

Record Status Badges

Requirements

Installation

Installation is via Composer:

$ composer require silverware/model-filters

Usage

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',
  ...
];

Status Field Positioning

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';
    }
}

Status Field Title

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';
}

Issues

Please use the GitHub issue tracker for bug reports and feature requests.

Contribution

Your contributions are gladly welcomed to help make this project better. Please see contributing for more information.

Maintainers

License

BSD-3-Clause © Praxis Interactive