silverstripe / segment-field
A reusable approach to segment-generating fields
Installs: 842 681
Dependents: 6
Suggesters: 0
Security: 0
Stars: 7
Watchers: 11
Forks: 16
Open Issues: 2
Type:silverstripe-vendormodule
Requires
- php: ^8.1
- silverstripe/cms: ^5
Requires (Dev)
- 4.x-dev
- 3.x-dev
- 3.3.x-dev
- 3.3.0
- 3.3.0-rc1
- 3.3.0-beta1
- 3.2.x-dev
- 3.2.2
- 3.2.1
- 3.2.0
- 3.2.0-rc1
- 3.2.0-beta1
- 3.1.x-dev
- 3.1.2
- 3.1.1
- 3.1.0
- 3.1.0-rc1
- 3.1.0-beta1
- 3.0.x-dev
- 3.0.0
- 3.0.0-rc1
- 3.0.0-beta1
- 2.x-dev
- 2.8.x-dev
- 2.8.1
- 2.8.0
- 2.8.0-rc1
- 2.8.0-beta1
- 2.7.x-dev
- 2.7.0
- 2.7.0-rc1
- 2.7.0-beta1
- 2.6.x-dev
- 2.6.0
- 2.6.0-rc1
- 2.6.0-beta1
- 2.5.x-dev
- 2.5.0
- 2.5.0-rc1
- 2.5.0-beta1
- 2.4.x-dev
- 2.4.0
- 2.4.0-rc1
- 2.4.0-beta1
- 2.4.0-alpha1
- 2.3.x-dev
- 2.3.0
- 2.3.0-rc1
- 2.3.0-beta1
- 2.2.x-dev
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.x-dev
- 2.1.1
- 2.1.0
- 2.0.0
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-dependabot/npm_and_yarn/cross-spawn-7.0.6
- dev-pulls/3/update-js-1725215732
- dev-2.7-release
- dev-master
This package is auto-updated.
Last update: 2024-11-20 23:11:26 UTC
README
A reusable approach to segment-generating fields.
Installation
composer require silverstripe/segment-field
Usage
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)
- Starting with a value of
"My New Page!"
. - The value is passed through
SlugSegmentFieldModifier
. - Preview value becomes
"My-New-Page"
, Input value becomes"My-New-Page"
. - The value is passed through
array('-', '')
. - Preview value becomes
"My-New-Page-"
, Input value becomes"My-New-Page"
. - The value is passed through
IDSegmentFieldModifier
. - Preview value becomes
"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.
Using on the frontend
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.
Versioning
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.
Thanks
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.