PageLinkBuilder extends AbstractTypolinkBuilder implements TypolinkBuilderInterface
Builds a TypoLink to a certain page
Table of Contents
Interfaces
- TypolinkBuilderInterface
- Used to generate a link to a page or file, an external URL or any other protocol in the frontend or backend.
Properties
- $cacheLifetimeCalculator : CacheLifetimeCalculator
- $contentObjectRenderer : ContentObjectRenderer
- $eventDispatcher : EventDispatcherInterface
- $features : Features
- $linkVarsCalculator : LinkVarsCalculator
- $recordAccessVoter : RecordAccessVoter
- $runtimeCache : FrontendInterface
- $siteFinder : SiteFinder
- $tcaSchemaFactory : TcaSchemaFactory
Methods
- __construct() : mixed
- _build() : LinkResultInterface
- This method is only here to keep BC for the build() method which will be removed in TYPO3 v15.0.
- buildLink() : LinkResultInterface
- 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
- getAbsRefPrefix() : string
- 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
- 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
$cacheLifetimeCalculator read-only
protected
CacheLifetimeCalculator
$cacheLifetimeCalculator
$contentObjectRenderer
protected
ContentObjectRenderer
$contentObjectRenderer
$eventDispatcher read-only
protected
EventDispatcherInterface
$eventDispatcher
$features read-only
protected
Features
$features
$linkVarsCalculator read-only
protected
LinkVarsCalculator
$linkVarsCalculator
$recordAccessVoter read-only
protected
RecordAccessVoter
$recordAccessVoter
$runtimeCache read-only
protected
FrontendInterface
$runtimeCache
Attributes
- #[Autowire]
- $service: 'cache.runtime'
$siteFinder read-only
protected
SiteFinder
$siteFinder
$tcaSchemaFactory read-only
protected
TcaSchemaFactory
$tcaSchemaFactory
Methods
__construct()
public
__construct(SiteFinder $siteFinder, EventDispatcherInterface $eventDispatcher, CacheLifetimeCalculator $cacheLifetimeCalculator, Features $features, TcaSchemaFactory $tcaSchemaFactory, RecordAccessVoter $recordAccessVoter, FrontendInterface $runtimeCache, LinkVarsCalculator $linkVarsCalculator) : mixed
Parameters
- $siteFinder : SiteFinder
- $eventDispatcher : EventDispatcherInterface
- $cacheLifetimeCalculator : CacheLifetimeCalculator
- $features : Features
- $tcaSchemaFactory : TcaSchemaFactory
- $recordAccessVoter : RecordAccessVoter
- $runtimeCache : FrontendInterface
- $linkVarsCalculator : LinkVarsCalculator
_build()
This method is only here to keep BC for the build() method which will be removed in TYPO3 v15.0.
public
_build(array<string|int, mixed> &$linkDetails, string $linkText, string $target, array<string|int, mixed> $conf, ServerRequestInterface $request, ContentObjectRenderer $contentObjectRenderer) : LinkResultInterface
The actual implementation should be done in buildLink() instead.
Parameters
- $linkDetails : array<string|int, mixed>
- $linkText : string
- $target : string
- $conf : array<string|int, mixed>
- $request : ServerRequestInterface
- $contentObjectRenderer : ContentObjectRenderer
this method will be removed in TYPO3 v15.0 again.
Return values
LinkResultInterfacebuildLink()
public
buildLink(array<string|int, mixed> $linkDetails, array<string|int, mixed> $configuration, ServerRequestInterface $request[, string $linkText = '' ]) : LinkResultInterface
Parameters
- $linkDetails : array<string|int, mixed>
-
parsed link details by the LinkService
- $configuration : array<string|int, mixed>
-
the TypoLink configuration array
- $request : ServerRequestInterface
- $linkText : string = ''
-
the link text
Return values
LinkResultInterfacegetMountPointParameterFromRootPointMaps()
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, ServerRequestInterface $request) : string
Parameters
- $pageId : int
-
Page id to return MPvar value for.
- $request : ServerRequestInterface
Return values
stringbuildPageRepository()
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
PageRepositorycalculateGlobalQueryParameters()
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
stringcalculateMountPointParameters()
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|nullcalculateQueryParameters()
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
stringcalculateUrlFragment()
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
stringencodeFallbackLinkTextIfLinkTextIsEmpty()
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[, ServerRequestInterface|null $request = null ]) : string
Parameters
- $url : string
-
The URL to be forced to be absolute
- $configuration : array<string|int, mixed>
-
TypoScript configuration of typolink
- $request : ServerRequestInterface|null = null
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, ServerRequestInterface $request) : UriInterface
Parameters
- $page : array<string|int, mixed>
- $siteOfTargetPage : Site
- $queryParameters : array<string|int, mixed>
- $fragment : string
- $conf : array<string|int, mixed>
- $request : ServerRequestInterface
Tags
Return values
UriInterfacegetAbsRefPrefix()
protected
getAbsRefPrefix(ServerRequestInterface $request) : string
Parameters
- $request : ServerRequestInterface
Return values
stringgetClosestMountPointValueForPage()
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
Return values
SiteInterface|nullgetCurrentSiteLanguage()
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|nullgetPageCacheTimeout()
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
intgetQueryArguments()
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
Return values
SiteLanguageinitializeMountPointMap()
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
boolmodifyUrlForAccessRestrictedPage()
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, ServerRequestInterface $request) : string
Parameters
- $url : string
- $page : array<string|int, mixed>
- $overridePageType : string
- $request : ServerRequestInterface
Tags
Return values
stringparseFallbackLinkTextIfLinkTextIsEmpty()
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
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[, ContentObjectRenderer|null $contentObjectRenderer = null ]) : string
Parameters
- $conf : array<string|int, mixed>
-
the typolink configuration
- $name : string
-
the key, usually "target", "extTarget" or "fileTarget"
- $contentObjectRenderer : ContentObjectRenderer|null = null
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, ServerRequestInterface $request) : bool
Only happens if the target is access restricted.
Parameters
- $conf : array<string|int, mixed>
- $page : array<string|int, mixed>
- $request : ServerRequestInterface