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
AbstractTypolinkBuilder constructor.
build()  : array|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.
getTypoScriptFrontendController()  : TypoScriptFrontendController
buildPageRepository()  : PageRepository
Builds PageRepository instance without depending on global context, e.g.
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. if null, this usually means that this class was called from CLI context.
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.
getSiteLanguageOfTargetPage()  : SiteLanguage
Fetches the requested language of a site that the link should be built for
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.
processUrl()  : string|null
Loops over all configured URL modifier hooks (if available) and returns the generated URL or NULL if no URL was generated.
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

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) : array|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

Tags

inheritdoc
throws
UnableToLinkException

Return values

array|LinkResultInterface —

an array with three parts (URL, Link Text, Target) - please note that in TYPO3 v12.0. this method will require to return a LinkResultInterface object

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

Previously located within TemplateService::getFromMPmap()

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

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. if null, this usually means that this class was called from CLI context.

protected getCurrentSite() : SiteInterface|null

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

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

Parameters

$url : string
$page : array
$overridePageType : string
$conf : array

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

Previously called TemplateService->initMPmap_create()

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()

processUrl()

Loops over all configured URL modifier hooks (if available) and returns the generated URL or NULL if no URL was generated.

protected processUrl(string $context, string $url[, array $typolinkConfiguration = [] ]) : string|null

Parameters

$context : string

The context in which the method is called (e.g. typoLink).

$url : string

The URL that should be processed.

$typolinkConfiguration : array = []

The current link configuration array.

Tags

throws
RuntimeException

if a hook was registered but did not fulfill the correct parameters.

Return values

string|null —

Returns NULL if URL was not processed or the processed URL as a string.

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[, bool $respectFrameSetOption = false ][, string $fallbackTarget = '' ]) : string

Parameters

$conf : array

the typolink configuration

$name : string

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

$respectFrameSetOption : bool = false

if set, then the fallback is only used as target if the doctype allows it

$fallbackTarget : string = ''

the string to be used when no target is found in the configuration

Return values

string —

the value of the target attribute, if there is one

On this page