PageLinkBuilder

class \TYPO3\CMS\Frontend\Typolink\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
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
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
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
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 &$linkDetails, string $linkText, string $target, array $conf) : LinkResultInterface

Parameters

$linkDetails : array

parsed link details by the LinkService

$linkText : string

the link text

$target : string

the target to point to

$conf : array

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 &$page, bool $disableGroupAccessCheck, string $linkText) : string|null

Parameters

$page : array
$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 &$conf, array $linkDetails) : array
  • 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
$linkDetails : array

Return values

array

calculateTargetAttribute()

Returns the final "target" attribute for a link.

protected calculateTargetAttribute(array $page, array $conf, bool $treatAsExternalLink, string $target) : string

Parameters

$page : array
$conf : array
$treatAsExternalLink : bool
$target : string

Return values

string

calculateUrlFragment()

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

protected calculateUrlFragment(array $conf, array $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
$linkDetails : array

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 $configuration) : string

Parameters

$url : string

The URL to be forced to be absolute

$configuration : array

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 $page, Site $siteOfTargetPage, array $queryParameters, string $fragment, array $conf) : UriInterface

Parameters

$page : array
$siteOfTargetPage : Site
$queryParameters : array
$fragment : string
$conf : array

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 $record) : int

Parameters

$record : array

Return values

int

getQueryArguments()

Gets the query arguments and assembles them for URLs.

protected getQueryArguments(bool|string|int $queryInformation, array $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

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

Parameters

$defaultMountPoints : string = ''

a string as defined in config.MP_defaults

$mapRootPointList : string = ''

a string as defined in config.MP_mapRootPoints

Return values

array

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 $page, string $overridePageType) : string

Parameters

$url : string
$page : array
$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 &$mountPointMap, int $id[, array $MP_array = [] ][, int $level = 0 ]) : void

Parameters

$mountPointMap : array

the exiting mount point map

$id : int

Root id from which to start map creation.

$MP_array : array = []

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 &$linkDetails, array &$configuration, bool $disableGroupAccessCheck) : array

Parameters

$linkDetails : array
$configuration : array
$disableGroupAccessCheck : bool

Return values

array

resolveShortcutPage()

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

protected resolveShortcutPage(array $page, PageRepository $pageRepository, bool $disableGroupAccessCheck) : array

Parameters

$page : array
$pageRepository : PageRepository
$disableGroupAccessCheck : bool

Return values

array

resolveTargetAttribute()

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

protected resolveTargetAttribute(array $conf, string $name) : string

Parameters

$conf : array

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 $page) : void

Parameters

$page : array

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 $conf, array $page) : bool

Only happens if the target is access restricted.

Parameters

$conf : array
$page : array

Tags

see
modifyUrlForAccessRestrictedPage

Return values

bool
On this page