SlugHelper
Generates, sanitizes and validates slugs for a TCA field
Table of Contents
Properties
- $configuration : array<string|int, mixed>
- $fieldName : string
- $prependSlashInSlug : bool
- Defines whether the slug field should start with "/".
- $tableName : string
- $workspaceEnabled : bool
- $workspaceId : int
Methods
- __construct() : mixed
- Slug constructor.
- buildSlugForUniqueInPid() : string
- Generate a slug with a suffix "/mytitle-1" if the suggested slug is in use already.
- buildSlugForUniqueInSite() : string
- Generate a slug with a suffix "/mytitle-1" if that is in use already.
- buildSlugForUniqueInTable() : string
- Generate a slug with a suffix "/mytitle-1" if that is in use already.
- extract() : string
- Extracts payload of slug and removes wrapping delimiters, e.g. `/hello/world/` will become `hello/world`.
- generate() : string
- Used when no slug exists for a record
- isUniqueInPid() : bool
- Checks if there are other records with the same slug that are located on the same PID.
- isUniqueInSite() : bool
- Check if there are other records with the same slug that are located on the same site.
- isUniqueInTable() : bool
- Check if there are other records with the same slug.
- sanitize() : string
- Cleans a slug value so it is used directly in the path segment of a URL.
- applyLanguageConstraint() : mixed
- Apply constraint to fetch records with same language (Slug / language should be unique).
- applyPageIdConstraint() : mixed
- applyRecordConstraint() : mixed
- applySlugConstraint() : mixed
- applyWorkspaceConstraint() : mixed
- buildSlug() : string
- Generate a slug with a suffix "/mytitle-1" if that is in use already.
- createPreparedQueryBuilder() : QueryBuilder
- flushRootLineCaches() : void
- Ensure root line caches are flushed to avoid any issue regarding moving of pages or dynamically creating sites while managing slugs at the same request
- resolveParentPageRecord() : array<string|int, mixed>|null
- Fetch a parent page, but exclude spacers, recyclers and sys-folders
- resolveVersionOverlays() : array<string|int, mixed>
Properties
$configuration
protected
array<string|int, mixed>
$configuration
= []
$fieldName
protected
string
$fieldName
$prependSlashInSlug
Defines whether the slug field should start with "/".
protected
bool
$prependSlashInSlug
For pages (due to rootline functionality), this is a must have, otherwise the root level page would have an empty value.
$tableName
protected
string
$tableName
$workspaceEnabled
protected
bool
$workspaceEnabled
$workspaceId
protected
int
$workspaceId
Methods
__construct()
Slug constructor.
public
__construct(string $tableName, string $fieldName, array<string|int, mixed> $configuration[, int $workspaceId = 0 ]) : mixed
Parameters
- $tableName : string
-
TCA table
- $fieldName : string
-
TCA field
- $configuration : array<string|int, mixed>
-
TCA configuration of the field
- $workspaceId : int = 0
-
the workspace ID to be working on.
buildSlugForUniqueInPid()
Generate a slug with a suffix "/mytitle-1" if the suggested slug is in use already.
public
buildSlugForUniqueInPid(string $slug, RecordState $state) : string
Parameters
- $slug : string
-
proposed slug
- $state : RecordState
Return values
stringbuildSlugForUniqueInSite()
Generate a slug with a suffix "/mytitle-1" if that is in use already.
public
buildSlugForUniqueInSite(string $slug, RecordState $state) : string
Parameters
- $slug : string
-
proposed slug
- $state : RecordState
Tags
Return values
stringbuildSlugForUniqueInTable()
Generate a slug with a suffix "/mytitle-1" if that is in use already.
public
buildSlugForUniqueInTable(string $slug, RecordState $state) : string
Parameters
- $slug : string
-
proposed slug
- $state : RecordState
Tags
Return values
stringextract()
Extracts payload of slug and removes wrapping delimiters, e.g. `/hello/world/` will become `hello/world`.
public
extract(string $slug) : string
Parameters
- $slug : string
Return values
stringgenerate()
Used when no slug exists for a record
public
generate(array<string|int, mixed> $recordData, int $pid) : string
Parameters
- $recordData : array<string|int, mixed>
- $pid : int
-
The uid of the page to generate the slug for
Return values
stringisUniqueInPid()
Checks if there are other records with the same slug that are located on the same PID.
public
isUniqueInPid(string $slug, RecordState $state) : bool
Parameters
- $slug : string
- $state : RecordState
Return values
boolisUniqueInSite()
Check if there are other records with the same slug that are located on the same site.
public
isUniqueInSite(string $slug, RecordState $state) : bool
Parameters
- $slug : string
- $state : RecordState
Tags
Return values
boolisUniqueInTable()
Check if there are other records with the same slug.
public
isUniqueInTable(string $slug, RecordState $state) : bool
Parameters
- $slug : string
- $state : RecordState
Tags
Return values
boolsanitize()
Cleans a slug value so it is used directly in the path segment of a URL.
public
sanitize(string $slug) : string
Parameters
- $slug : string
Return values
stringapplyLanguageConstraint()
Apply constraint to fetch records with same language (Slug / language should be unique).
protected
applyLanguageConstraint(QueryBuilder $queryBuilder, int $languageId) : mixed
If language is -1 (all languages), there should not be any other records with the same slug of any language (or -1).
Parameters
- $queryBuilder : QueryBuilder
- $languageId : int
applyPageIdConstraint()
protected
applyPageIdConstraint(QueryBuilder $queryBuilder, int $pageId) : mixed
Parameters
- $queryBuilder : QueryBuilder
- $pageId : int
applyRecordConstraint()
protected
applyRecordConstraint(QueryBuilder $queryBuilder, string|int $recordId) : mixed
Parameters
- $queryBuilder : QueryBuilder
- $recordId : string|int
applySlugConstraint()
protected
applySlugConstraint(QueryBuilder $queryBuilder, string $slug) : mixed
Parameters
- $queryBuilder : QueryBuilder
- $slug : string
applyWorkspaceConstraint()
protected
applyWorkspaceConstraint(QueryBuilder $queryBuilder, RecordState $state) : mixed
Parameters
- $queryBuilder : QueryBuilder
- $state : RecordState
buildSlug()
Generate a slug with a suffix "/mytitle-1" if that is in use already.
protected
buildSlug(string $slug, RecordState $state, callable $isUnique) : string
Parameters
- $slug : string
-
proposed slug
- $state : RecordState
- $isUnique : callable
-
Callback to check for uniqueness
Tags
Return values
stringcreatePreparedQueryBuilder()
protected
createPreparedQueryBuilder() : QueryBuilder
Return values
QueryBuilderflushRootLineCaches()
Ensure root line caches are flushed to avoid any issue regarding moving of pages or dynamically creating sites while managing slugs at the same request
protected
flushRootLineCaches() : void
resolveParentPageRecord()
Fetch a parent page, but exclude spacers, recyclers and sys-folders
protected
resolveParentPageRecord(int $pid, int $languageId) : array<string|int, mixed>|null
Parameters
- $pid : int
- $languageId : int
Return values
array<string|int, mixed>|nullresolveVersionOverlays()
protected
resolveVersionOverlays(array<string|int, mixed> $records) : array<string|int, mixed>
Parameters
- $records : array<string|int, mixed>