CoolCMS API

AdminPageHrefTranslator
in package

Translates pretty admin URLs: a per-language pair (`presenterHref`, `actionHref`) to the Nette presenter and action of an admin page, and back.

The data lives on the admin page:

  • AdminPage::getPresenter() is the module path plus presenter (:Admin:Company:Setting),
  • AdminPage::getAction() is the action (show),
  • AdminPageText::getPresenterHref() / getActionHref() are the per-language URL segments.

The page with frontpage set is the default target (URL admin without segments). The cache fills lazily on first use, so ordinary front requests pay no extra DB query.

Table of Contents

Constants

DefaultLocale  : mixed = 'cs'
Default locale (same as the default in the route mask `<loc=cs ...>`).
TargetSeparator  : mixed = '::'
Separator of presenter and action in cache keys.

Properties

$adminPageManager  : AdminPageManager
$frontpageKey  : string|null
$frontpageTarget  : array{presenter: string, action: string}|null
$hrefToTarget  : array<int, array<string, array{presenter: string, action: string}>>
$localeResolver  : LocaleResolver
$targetToHref  : array<int, array<string, array{presenterHref: string, actionHref: string}>>
$warmedUp  : bool

Methods

__construct()  : mixed
resolveHref()  : array{presenterHref: ?string, actionHref: ?string}|null
Resolves a target presenter and action to the pretty URL.
resolveTarget()  : array{presenter: string, action: string}|null
Resolves a pretty URL to the target presenter and action.
hrefKey()  : string
Key of the `href` to target map, lowercase so that letter case in the URL does not cause a 404.
normalizePresenter()  : string
Converts `:Admin:Company:Setting` to `Company:Setting` (relative to the Admin module).
resolveLanguageId()  : int|null
warmup()  : void
Lazily loads all admin pages with translations and builds the maps for both directions.

Constants

DefaultLocale

Default locale (same as the default in the route mask `<loc=cs ...>`).

private mixed DefaultLocale = 'cs'

TargetSeparator

Separator of presenter and action in cache keys.

private mixed TargetSeparator = '::'

Properties

$frontpageKey

private string|null $frontpageKey = null

identity of the frontpage target (presenter::action), used to detect it in the reverse direction

$frontpageTarget

private array{presenter: string, action: string}|null $frontpageTarget = null

target of the frontpage page (same in all languages)

$hrefToTarget

private array<int, array<string, array{presenter: string, action: string}>> $hrefToTarget = []

[langId]["ph/ah"] => target

$targetToHref

private array<int, array<string, array{presenterHref: string, actionHref: string}>> $targetToHref = []

[langId]["presenter::action"] => href

Methods

resolveHref()

Resolves a target presenter and action to the pretty URL.

public resolveHref(string $presenter, string $action, string|null $locale) : array{presenterHref: ?string, actionHref: ?string}|null

$presenter is relative to the Admin module (without the Admin: prefix), as the Nette RouteList passes it when building a URL.

Parameters
$presenter : string
$action : string
$locale : string|null
Return values
array{presenterHref: ?string, actionHref: ?string}|null —

null when the page has no pretty URL (falls back to the generic route); null values mean the frontpage page, URL admin without segments.

resolveTarget()

Resolves a pretty URL to the target presenter and action.

public resolveTarget(string|null $presenterHref, string|null $actionHref, string|null $locale) : array{presenter: string, action: string}|null
Parameters
$presenterHref : string|null
$actionHref : string|null
$locale : string|null
Return values
array{presenter: string, action: string}|null —

null when no page matches (the route is skipped)

hrefKey()

Key of the `href` to target map, lowercase so that letter case in the URL does not cause a 404.

private static hrefKey(string $presenterHref, string $actionHref) : string
Parameters
$presenterHref : string
$actionHref : string
Return values
string

normalizePresenter()

Converts `:Admin:Company:Setting` to `Company:Setting` (relative to the Admin module).

private normalizePresenter(string $presenter) : string
Parameters
$presenter : string
Return values
string

resolveLanguageId()

private resolveLanguageId(string|null $locale) : int|null
Parameters
$locale : string|null
Return values
int|null

warmup()

Lazily loads all admin pages with translations and builds the maps for both directions.

private warmup() : void
On this page

Search results