Adds an extension to add a URLSegment to any SilverStripe DataObject and manages slug collisions
Adds an extension to add a URLSegment to any SilverStripe DataObject and manages slug collisions.
That is, it does the basic lifting of:
URLSegment
field of type DBVarchar
to your objectSilverStripe 4
composer require fromholdio/silverstripe-urlsegmenter
It's all plug-n-play once you apply the extension to your data object - with one exception.
To allow the extension to auto-generate a slug and manage collisions, you need to tell the extension what the scope of the collection you're setting the URLSegment within is.
class Widget extends DataObject
{
// or apply via config.yml
private static $extensions = [
URLSegmenter::class
];
private static $db = [
'Title' => 'Varchar'
];
private static $has_one = [
'WidgetCategory' => WidgetCategory::class
];
public function getURLSegmenterScope()
{
return self::get()
->filter('WidgetCategoryID' => $this->WidgetCategoryID)
->exclude('ID', $this->ID);
}
}
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