PageLinkBuilder extends AbstractTypolinkBuilder

Builds a TypoLink to a certain page

Table of Contents

Properties

$contentObjectRenderer  : ContentObjectRenderer
$typoScriptFrontendController  : TypoScriptFrontendController|null

Methods

__construct()  : mixed
build()  : LinkResultInterface
Should be implemented by all subclasses to return an array with three parts: - URL - Link Text (can be modified) - Target (can be modified) - Tag Attributes (optional)
getMountPointParameterFromRootPointMaps()  : string
Initializes the automatically created mountPointMap coming from the "config.MP_mapRootPoints" setting Can be called many times with overhead only the first time since then the map is generated and cached in memory.
buildPageRepository()  : PageRepository
Builds PageRepository instance without depending on global context, e.g.
calculateGlobalQueryParameters()  : string
Get "global" query parameters that should be added.
calculateMountPointParameters()  : string|null
Calculates a possible "&MP=" GET parameter for this link when using mount points.
calculateQueryParameters()  : array<string|int, mixed>
Takes all given options into account to calculate the additional GET parameters for the link, and returns them as a clean array without duplicates.
calculateTargetAttribute()  : string
Returns the final "target" attribute for a link.
calculateUrlFragment()  : string
Checks for the stdWrap "section" which returns the fragment for the generated URL.
encodeFallbackLinkTextIfLinkTextIsEmpty()  : string
Helper method to a fallback method properly encoding HTML.
forceAbsoluteUrl()  : string
Forces a given URL to be absolute.
generateUrlForPageWithSiteConfiguration()  : UriInterface
Create a UriInterface object when linking to a page with a site configuration
getClosestMountPointValueForPage()  : string
The function will do its best to find a MP value that will keep the page id inside the current Mount Point rootline if any.
getCurrentSite()  : SiteInterface|null
Check if we have a site object in the current request.
getCurrentSiteLanguage()  : SiteLanguage|null
If the current request has a site language, this means that the SiteResolver has detected a page with a site configuration and a selected language, so let's choose that one.
getPageCacheTimeout()  : int
Get the cache lifetime for the given page record.
getQueryArguments()  : string
Gets the query arguments and assembles them for URLs.
getSiteLanguageOfTargetPage()  : SiteLanguage
Fetches the requested language of a site that the link should be built for
getTypoScriptFrontendController()  : TypoScriptFrontendController
initializeMountPointMap()  : array<string|int, mixed>
Create mount point map, based on TypoScript config.MP_mapRootPoints and config.MP_defaults.
isLibParseFuncDefined()  : bool
Determines whether lib.parseFunc is defined.
modifyUrlForAccessRestrictedPage()  : string
If the target page is access restricted, and globally configured to be linked to a different page (e.g. login page) via config.typolinkLinkAccessRestrictedPages = 123 then the URL is modified.
parseFallbackLinkTextIfLinkTextIsEmpty()  : string
Helper method to a fallback method parsing HTML out of it
populateMountPointMapForPageRecursively()  : void
Creating mountPointMap for a certain ID root point.
resolvePage()  : array<string|int, mixed>
Resolves page and if a translated page was found, resolves that to its language parent, adjusts `$linkDetails['pageuid']` (for hook processing) and modifies `$configuration['language']` (for language URL generation).
resolveShortcutPage()  : array<string|int, mixed>
Checks if page is a shortcut, then resolves the target page directly
resolveTargetAttribute()  : string
Creates the value for target="..." in a typolink configuration
sendCacheTagEvent()  : void
shouldModifyUrlForAccessRestrictedPage()  : bool
Checks if config.typolinkLinkAccessRestrictedPages is set to a specific page target, and the current link configuration typolink.linkAccessRestrictedPages is not set (= which would directly link to page that is access restricted).

Properties

Methods

build()

Should be implemented by all subclasses to return an array with three parts: - URL - Link Text (can be modified) - Target (can be modified) - Tag Attributes (optional)

public build(array<string|int, mixed> &$linkDetails, string $linkText, string $target, array<string|int, mixed> $conf) : LinkResultInterface
Parameters
$linkDetails : array<string|int, mixed>

parsed link details by the LinkService

$linkText : string

the link text

$target : string

the target to point to

$conf : array<string|int, mixed>

the TypoLink configuration array

Return values
LinkResultInterface

getMountPointParameterFromRootPointMaps()

Initializes the automatically created mountPointMap coming from the "config.MP_mapRootPoints" setting Can be called many times with overhead only the first time since then the map is generated and cached in memory.

public getMountPointParameterFromRootPointMaps(int $pageId) : string
Parameters
$pageId : int

Page id to return MPvar value for.

Return values
string

buildPageRepository()

Builds PageRepository instance without depending on global context, e.g.

protected buildPageRepository([LanguageAspect|null $languageAspect = null ]) : PageRepository

not automatically overlaying records based on current request language.

Parameters
$languageAspect : LanguageAspect|null = null
Return values
PageRepository

calculateGlobalQueryParameters()

Get "global" query parameters that should be added.

protected calculateGlobalQueryParameters() : string

Depends on given request query parameters plus config.linkVars TypoScript setting plus eventually special arguments for logged in Backend users.

Return values
string

calculateMountPointParameters()

Calculates a possible "&MP=" GET parameter for this link when using mount points.

protected calculateMountPointParameters(array<string|int, mixed> &$page, bool $disableGroupAccessCheck, string $linkText) : string|null
Parameters
$page : array<string|int, mixed>
$disableGroupAccessCheck : bool
$linkText : string
Return values
string|null

calculateQueryParameters()

Takes all given options into account to calculate the additional GET parameters for the link, and returns them as a clean array without duplicates.

protected calculateQueryParameters(array<string|int, mixed> &$conf, array<string|int, mixed> $linkDetails) : array<string|int, mixed>
  • addQueryString
  • additionalParams (+ the ones added from "parameter")
  • config.linkVars
  • type (from "parameter")
  • no_cache

This also does a transformation to remove "L" and "_language" arguments and put this into the $conf array.

Mount Points are added later-on.

Parameters
$conf : array<string|int, mixed>
$linkDetails : array<string|int, mixed>
Return values
array<string|int, mixed>

calculateTargetAttribute()

Returns the final "target" attribute for a link.

protected calculateTargetAttribute(array<string|int, mixed> $page, array<string|int, mixed> $conf, bool $treatAsExternalLink, string $target) : string
Parameters
$page : array<string|int, mixed>
$conf : array<string|int, mixed>
$treatAsExternalLink : bool
$target : string
Return values
string

calculateUrlFragment()

Checks for the stdWrap "section" which returns the fragment for the generated URL.

protected calculateUrlFragment(array<string|int, mixed> $conf, array<string|int, mixed> $linkDetails) : string

Detail: When using a section as an integer, a "c" is added, which referes to a tt_content element. see https://forge.typo3.org/issues/19832 for further work on this limitation.

Parameters
$conf : array<string|int, mixed>
$linkDetails : array<string|int, mixed>
Return values
string

encodeFallbackLinkTextIfLinkTextIsEmpty()

Helper method to a fallback method properly encoding HTML.

protected encodeFallbackLinkTextIfLinkTextIsEmpty(string $originalLinkText, string $fallbackLinkText) : string
Parameters
$originalLinkText : string

the original string, if empty, the fallback link text

$fallbackLinkText : string

the string to be used.

Return values
string

the final text

forceAbsoluteUrl()

Forces a given URL to be absolute.

protected forceAbsoluteUrl(string $url, array<string|int, mixed> $configuration) : string
Parameters
$url : string

The URL to be forced to be absolute

$configuration : array<string|int, mixed>

TypoScript configuration of typolink

Return values
string

The absolute URL

generateUrlForPageWithSiteConfiguration()

Create a UriInterface object when linking to a page with a site configuration

protected generateUrlForPageWithSiteConfiguration(array<string|int, mixed> $page, Site $siteOfTargetPage, array<string|int, mixed> $queryParameters, string $fragment, array<string|int, mixed> $conf) : UriInterface
Parameters
$page : array<string|int, mixed>
$siteOfTargetPage : Site
$queryParameters : array<string|int, mixed>
$fragment : string
$conf : array<string|int, mixed>
Tags
throws
UnableToLinkException
Return values
UriInterface

getClosestMountPointValueForPage()

The function will do its best to find a MP value that will keep the page id inside the current Mount Point rootline if any.

protected getClosestMountPointValueForPage(int $pageId) : string
Parameters
$pageId : int

page id

Return values
string

MP value, prefixed with &MP= (depending on $raw)

getCurrentSite()

Check if we have a site object in the current request.

protected getCurrentSite() : SiteInterface|null

If null, this usually means that this class was called from CLI context.

Tags
todo:

We may want to see if we can't require a site object to be always set and fail here otherwise!

Return values
SiteInterface|null

getCurrentSiteLanguage()

If the current request has a site language, this means that the SiteResolver has detected a page with a site configuration and a selected language, so let's choose that one.

protected getCurrentSiteLanguage() : SiteLanguage|null
Return values
SiteLanguage|null

getPageCacheTimeout()

Get the cache lifetime for the given page record.

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

getQueryArguments()

Gets the query arguments and assembles them for URLs.

protected getQueryArguments(bool|string|int $queryInformation, array<string|int, mixed> $configuration) : string

By default, only the resolved query arguments from the route are used, using "untrusted" as $queryInformation allows to also include ANY query parameter - use with care.

Arguments may be removed or set, depending on configuration.

Parameters
$queryInformation : bool|string|int

is set to "1", "true", "0", "false" or "untrusted"

$configuration : array<string|int, mixed>

Configuration

Return values
string

The URL query part (starting with a &) or empty

getSiteLanguageOfTargetPage()

Fetches the requested language of a site that the link should be built for

protected getSiteLanguageOfTargetPage(Site $siteOfTargetPage, string $targetLanguageId) : SiteLanguage
Parameters
$siteOfTargetPage : Site
$targetLanguageId : string

"current" or the languageId

Tags
throws
UnableToLinkException
Return values
SiteLanguage

initializeMountPointMap()

Create mount point map, based on TypoScript config.MP_mapRootPoints and config.MP_defaults.

protected initializeMountPointMap([string $defaultMountPoints = '' ][, string $mapRootPointList = '' ]) : array<string|int, mixed>
Parameters
$defaultMountPoints : string = ''

a string as defined in config.MP_defaults

$mapRootPointList : string = ''

a string as defined in config.MP_mapRootPoints

Return values
array<string|int, mixed>

isLibParseFuncDefined()

Determines whether lib.parseFunc is defined.

protected isLibParseFuncDefined() : bool
Return values
bool

modifyUrlForAccessRestrictedPage()

If the target page is access restricted, and globally configured to be linked to a different page (e.g. login page) via config.typolinkLinkAccessRestrictedPages = 123 then the URL is modified.

protected modifyUrlForAccessRestrictedPage(string $url, array<string|int, mixed> $page, string $overridePageType) : string
Parameters
$url : string
$page : array<string|int, mixed>
$overridePageType : string
Tags
see
shouldModifyUrlForAccessRestrictedPage
Return values
string

parseFallbackLinkTextIfLinkTextIsEmpty()

Helper method to a fallback method parsing HTML out of it

protected parseFallbackLinkTextIfLinkTextIsEmpty(string $originalLinkText, string $fallbackLinkText) : string
Parameters
$originalLinkText : string

the original string, if empty, the fallback link text

$fallbackLinkText : string

the string to be used.

Return values
string

the final text

populateMountPointMapForPageRecursively()

Creating mountPointMap for a certain ID root point.

protected populateMountPointMapForPageRecursively(array<string|int, mixed> &$mountPointMap, int $id[, array<string|int, mixed> $MP_array = [] ][, int $level = 0 ]) : void
Parameters
$mountPointMap : array<string|int, mixed>

the exiting mount point map

$id : int

Root id from which to start map creation.

$MP_array : array<string|int, mixed> = []

MP_array passed from root page.

$level : int = 0

Recursion brake. Incremented for each recursive call. 20 is the limit.

Tags
see
getMountPointParameterFromRootPointMaps()

resolvePage()

Resolves page and if a translated page was found, resolves that to its language parent, adjusts `$linkDetails['pageuid']` (for hook processing) and modifies `$configuration['language']` (for language URL generation).

protected resolvePage(array<string|int, mixed> &$linkDetails, array<string|int, mixed> &$configuration, bool $disableGroupAccessCheck) : array<string|int, mixed>
Parameters
$linkDetails : array<string|int, mixed>
$configuration : array<string|int, mixed>
$disableGroupAccessCheck : bool
Return values
array<string|int, mixed>

resolveShortcutPage()

Checks if page is a shortcut, then resolves the target page directly

protected resolveShortcutPage(array<string|int, mixed> $page, PageRepository $pageRepository, bool $disableGroupAccessCheck) : array<string|int, mixed>
Parameters
$page : array<string|int, mixed>
$pageRepository : PageRepository
$disableGroupAccessCheck : bool
Return values
array<string|int, mixed>

resolveTargetAttribute()

Creates the value for target="..." in a typolink configuration

protected resolveTargetAttribute(array<string|int, mixed> $conf, string $name) : string
Parameters
$conf : array<string|int, mixed>

the typolink configuration

$name : string

the key, usually "target", "extTarget" or "fileTarget"

Return values
string

the value of the target attribute, if there is one

sendCacheTagEvent()

protected sendCacheTagEvent(array<string|int, mixed> $page) : void
Parameters
$page : array<string|int, mixed>

shouldModifyUrlForAccessRestrictedPage()

Checks if config.typolinkLinkAccessRestrictedPages is set to a specific page target, and the current link configuration typolink.linkAccessRestrictedPages is not set (= which would directly link to page that is access restricted).

protected shouldModifyUrlForAccessRestrictedPage(array<string|int, mixed> $conf, array<string|int, mixed> $page) : bool

Only happens if the target is access restricted.

Parameters
$conf : array<string|int, mixed>
$page : array<string|int, mixed>
Tags
see
modifyUrlForAccessRestrictedPage
Return values
bool

        
On this page

Search results