Nightjar\Slug\Slug
Adds a 'url slug' property to DataObject classes, in order for them to be able to be loaded via a URL through a{@see SilverStripe\Control\Controller}. The typical use case for this is to view records related to a {@see Page}, to be able to have a controller action that doesn't need to reference the ID ofthe record.
E.g. /products/nice-jacket - where this is /pageType/relatedObject-notAPage
To simplify the controller section of this purpose
Synopsis
class Slug
extends DataExtension
{
- // constants
- const ACTIVE_NONE = NULL;
- const ACTIVE_SECTION = false;
- const ACTIVE_CURRENT = true;
- // members
- private static array $db = ;
- private static array $indexes = ;
- protected $fieldToSlug;
- protected string|null $relationName;
- protected $enforceParity;
- protected null|boolean $active = NULL;
- // methods
- public void __construct()
- public void setOwner()
- public DataObject setSlugActive()
- public string getSlug()
- public void onBeforeWrite()
- public void updateCMSFields()
- public string Link()
- public boolean isCurrent()
- public boolean isSection()
- public string LinkOrCurrent()
- public string LinkOrSection()
- public string LinkingMode()
Hierarchy
Extends
- SilverStripe\ORM\DataExtension
Constants
Name | Value |
---|---|
ACTIVE_NONE | NULL |
ACTIVE_SECTION | false |
ACTIVE_CURRENT | true |
Members
private
- $db
- $indexes
protected
- $active
—
Nightjar\Slug\null|boolean
The owner has been accessed via a route involving the URLSlug Tri state; current, section, none - $enforceParity
—
boolean
Whether or not we should update the URLSlug field when the field to slug changes - $fieldToSlug
—
string
The field on the owner that we should take the value from in order to generate a slug - $relationName
—
Nightjar\Slug\string|null
If we should restrict the slugging uniqueness to a certain subset of the owner class, this will be the name of the relation to filter by to detect uniqueness
Methods
public
- __construct() — Apply extension with configurable defaults
- Link() — Get the link to be able to request this (owner) object from a URL The nature of a DataExtension is that this can be overridden at any time by defining the `Link($action = null)` method on the owner class.
- LinkOrCurrent() — Return "link" or "section" depending on if this is the current viewing object.
- LinkOrSection() — Return "link" or "section" depending on if this is the current section.
- LinkingMode() — Return "current", "section", or "link" depending on if this page is the slugged item currently being viewed, in the section (an ancestor of the current), or simply exists - respectively.
- getSlug() — Generate a url slug segment
- isCurrent() — Returns true if this is the slugged object being used to handle this request.
- isSection() — Check if this slugged object is in the currently active section (i.e. it, or one of its children is currently being viewed).
- onBeforeWrite() — Check for collisions, iff we need to update the slug and upate the model with the confirmedsafe value before writing
- setOwner()
- setSlugActive() — Set whether this slugged item is being viewed {@see self::ACTIVE_NONE} {@see self::ACTIVE_SECTION} {@see self::ACTIVE_CURRENT}
- updateCMSFields()