Nightjar\Slug\SlugHandler
This is for handling a request for a slugged DataObject, and should be applied to a Controller.
One can either supply the method name (to get slugs from) as a string to the constructor,
or define a slug_trails property on the Controller.
The latter allows support for multiple slugged relationships to reside on the same
, and the `slug_trails` property is an array map
in the format of
[ $Trail => $RelationshipName, ... ]
where $Trail is the URL segment it is loaded over,
and $RelationshipName is the internal method to call to resolve the $Slug parameter
of the url_handler.
a.k.a.
MyController:
slug_trails:
'news' => 'NewsArticles'
Synopsis
class SlugHandler
extends Extension
{
- // members
- private static array $url_handlers = ;
- private static array $allowed_actions = ;
- protected null|array $slugs;
- protected $dataSource;
- // methods
- public void __construct()
- protected DataObject findSlug()
- public array handleSlug()
Hierarchy
Extends
- SilverStripe\Core\Extension
Members
private
- $allowed_actions
- $url_handlers
—
array
We must define these statically up front, so we cannot tell if the model we'd otherwise be handling has only one slugged relationship, or many of them. In the former case the simple $Slug is sufficient, but if there are many releationships we require $Trail in order to follow to the correct slug. So both routes are defiend.
protected
- $dataSource
—
array
Which function on the Controller will get us the initial DataObject? - $slugs
—
Nightjar\Slug\null|array
Holds relationship info for single slugged relationship objects, if passed to the constructor
Methods
protected
- findSlug() — Fetches the slugged item at the end of a route (slime trail).
public
- __construct() — Apply extension to {@see SilverStripe\Control\Controller}.
- handleSlug() — Process a request for a slugged item.