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 "/".
$slugNormalizer  : SlugNormalizer
$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 and sys-folders
resolveVersionOverlays()  : array<string|int, mixed>

Properties

$configuration

protected array<string|int, mixed> $configuration = []

$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.

$workspaceEnabled

protected bool $workspaceEnabled

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
string

buildSlugForUniqueInSite()

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
throws
SiteNotFoundException
Return values
string

buildSlugForUniqueInTable()

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
throws
SiteNotFoundException
Return values
string

extract()

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
string

generate()

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
string

isUniqueInPid()

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
bool

isUniqueInSite()

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
throws
SiteNotFoundException
Return values
bool

sanitize()

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
string

applyLanguageConstraint()

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

applyRecordConstraint()

protected applyRecordConstraint(QueryBuilder $queryBuilder, string|int $recordId) : mixed
Parameters
$queryBuilder : QueryBuilder
$recordId : string|int

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
throws
SiteNotFoundException
Return values
string

flushRootLineCaches()

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 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>|null

resolveVersionOverlays()

protected resolveVersionOverlays(array<string|int, mixed> $records) : array<string|int, mixed>
Parameters
$records : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results