A reusable approach to segment-generating fields.
use SilverStripe\Forms\SegmentField;
use SilverStripe\Forms\SegmentFieldModifier\SlugSegmentFieldModifier;
use SilverStripe\Forms\SegmentFieldModifier\IDSegmentFieldModifier;
SegmentField::create('PageName')->setModifiers(array(
SlugSegmentFieldModifier::create()->setDefault('page'),
array('-', ''),
IDSegmentFieldModifier::create(),
))->setPreview($this->PageDisplayName)
"My New Page!"
.SlugSegmentFieldModifier
."My-New-Page"
, Input value becomes "My-New-Page"
.array('-', '')
."My-New-Page-"
, Input value becomes "My-New-Page"
.IDSegmentFieldModifier
."My-New-Page-1"
(with the DataObject ID), Input value becomes "My-New-Page"
.You can pass any similarly structured array or implementation of SilverStripe\Forms\SegmentFieldModifier
in the modifiers list.
This field is primarily designed for use within the SilverStripe CMS. If you want to use it on the frontend, please
ensure that you have included your own version of jQuery and the jQuery entwine library that ships with the
silverstripe/admin module, for example:
Requirements::javascript('//code.jquery.com/jquery-3.3.1.min.js');
Requirements::javascript('silverstripe/admin:thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
These dependencies are included by default when using this field within the CMS.
This library follows Semver. According to Semver, you will be able to upgrade to any minor or patch version of this library without any breaking changes to the public API. Semver also requires that we clearly define the public API for this library.
All methods, with public
visibility, are part of the public API. All other methods are not part of the public API. Where possible, we'll try to keep protected
methods backwards-compatible in minor/patch versions, but if you're overriding methods then please test your work before upgrading.
I'd like to thank SilverStripe for letting me work on fun projects like this. Feel free to talk to me about using the framework and CMS or working at SilverStripe.
Module rating system helping users find modules that are well supported. For more on how the rating system works visit Module standards
Score not correct? Let us know there is a problem
None
None