PreviewUriBuilder

readonly class \TYPO3\CMS\Workspaces\Preview\PreviewUriBuilder

Create links to pages when in a workspace for previewing purposes

Attributes

#[Autoconfigure]
$public: true

Table of Contents

Methods

__construct()  : mixed
buildUriForElement()  : string
Generates a view URI for an element.
buildUriForElementWithToken()  : string
Generates a shareable workspace preview link for any element.
buildUriForPage()  : string
Generates a workspace preview link.
buildUriForWorkspaceSplitPreview()  : UriInterface
Generates a workspace split-bar preview link.
buildUrisForAllLanguagesOfPage()  : array
Generate workspace preview links for all available languages of a page
compilePreviewKeyword()  : string
Adds an entry to the sys_preview database table and return the preview keyword.
createPreviewUriForElement()  : UriInterface|null
getAvailableLanguages()  : array
Get the available languages of a certain page, including language=0 if the user has access to it.
getBackendUser()  : BackendUserAuthentication
getLivePageUid()  : int
Find the Live-Uid for a given page uid and runtime cache the result to avoid too many database-queries.
getPreviewLinkLifetime()  : int
Determine the number of hours a preview link should be valid after creation, default 48 hours.
resolvePreviewPageId()  : int
Resolves the preview page ID for a given record.
resolvePreviewQueryParameters()  : array
Resolves additional query parameters for non-page record previews.

Methods

__construct()

public __construct(EventDispatcherInterface $eventDispatcher, FrontendInterface $runtimeCache, SiteFinder $siteFinder, UriBuilder $uriBuilder, ConnectionPool $connectionPool, TranslationConfigurationProvider $translationConfigurationProvider, TcaSchemaFactory $tcaSchemaFactory) : mixed

Parameters

$eventDispatcher : EventDispatcherInterface
$runtimeCache : FrontendInterface
$siteFinder : SiteFinder
$uriBuilder : UriBuilder
$connectionPool : ConnectionPool
$translationConfigurationProvider : TranslationConfigurationProvider
$tcaSchemaFactory : TcaSchemaFactory

buildUriForElement()

Generates a view URI for an element.

public buildUriForElement(string $table, int $uid[, array|null $liveRecord = null ][, array|null $versionRecord = null ]) : string

Parameters

$table : string

Table to be used

$uid : int

Uid of the version(!) record

$liveRecord : array|null = null
$versionRecord : array|null = null

Return values

string

buildUriForElementWithToken()

Generates a shareable workspace preview link for any element.

public buildUriForElementWithToken(string $table, int $uid[, int $languageId = LanguageMarker::DEFAULT_LANGUAGE ][, array|null $liveRecord = null ][, array|null $versionRecord = null ]) : string

This creates a preview URL with an ADMCMD_prev token that allows viewing workspace content without requiring a backend login. The token is stored in the sys_preview table and has a configurable lifetime.

Parameters

$table : string

Table to be used

$uid : int

Uid of the version(!) record

$languageId : int = LanguageMarker::DEFAULT_LANGUAGE

The language ID for the preview

$liveRecord : array|null = null
$versionRecord : array|null = null

Return values

string

buildUriForPage()

Generates a workspace preview link.

public buildUriForPage(int $uid[, int $languageId = LanguageMarker::DEFAULT_LANGUAGE ]) : string

Parameters

$uid : int

The ID of the record to be linked

$languageId : int = LanguageMarker::DEFAULT_LANGUAGE

the language to link to

Return values

string —

the full domain including the protocol http:// or https://, but without the trailing '/'

buildUriForWorkspaceSplitPreview()

Generates a workspace split-bar preview link.

public buildUriForWorkspaceSplitPreview(int $uid) : UriInterface

Parameters

$uid : int

The ID of the record to be linked

Tags

throws
RouteNotFoundException

Return values

UriInterface

buildUrisForAllLanguagesOfPage()

Generate workspace preview links for all available languages of a page

public buildUrisForAllLanguagesOfPage(int $pageId) : array

Parameters

$pageId : int

Return values

array

compilePreviewKeyword()

Adds an entry to the sys_preview database table and return the preview keyword.

protected compilePreviewKeyword() : string

Cached in runtime cache to only create one link per request, even if the service method is called multiple times.

Return values

string —

Returns a 32 byte MD5 hash keyword for use in URL for ADMCMD_prev=[keyword]

createPreviewUriForElement()

protected createPreviewUriForElement(string $table, int $uid[, array|null $liveRecord = null ][, array|null $versionRecord = null ]) : UriInterface|null

Parameters

$table : string
$uid : int
$liveRecord : array|null = null
$versionRecord : array|null = null

Return values

UriInterface|null

getAvailableLanguages()

Get the available languages of a certain page, including language=0 if the user has access to it.

protected getAvailableLanguages(int $pageId) : array

Parameters

$pageId : int

Return values

array —

assoc array with the languageId as key and the languageTitle as value

getLivePageUid()

Find the Live-Uid for a given page uid and runtime cache the result to avoid too many database-queries.

protected getLivePageUid(int $uid) : int

Parameters

$uid : int

Return values

int

getPreviewLinkLifetime()

Determine the number of hours a preview link should be valid after creation, default 48 hours.

protected getPreviewLinkLifetime() : int

Return values

int

resolvePreviewPageId()

Resolves the preview page ID for a given record.

protected resolvePreviewPageId(string $table, array $liveRecord, array $versionRecord) : int

Parameters

$table : string
$liveRecord : array
$versionRecord : array

Return values

int

resolvePreviewQueryParameters()

Resolves additional query parameters for non-page record previews.

protected resolvePreviewQueryParameters(string $table, int $previewPageId, array $liveRecord, array $versionRecord) : array

Parameters

$table : string
$previewPageId : int
$liveRecord : array
$versionRecord : array

Return values

array
On this page