CoolCMS API

EditorLinkTrait

Backend of the "page link" button in TinyMCE (admin `tinymce-page-link.js`).

Returns a ready URL, not a slug: the page address is built by the route assigned to the page (many-to-many page.routes), so /o-nas and /blog/clanek come out right and nothing is assembled by hand. Same procedure as the front end menu (MenuComponent/.../parts/Link.latte): target :<module>:<presenter>:<action> and slug = PageText::getHref().

It is a signal (handle*) because of the automatic same-origin CSRF protection of Nette 3.2+; see EditorUploadTrait.

Table of Contents

Constants

EDITOR_PAGE_LIMIT  : mixed = 500
Listing cap; the dialog is a suggester, not a paged list.
EDITOR_PAGE_TARGETS  : mixed = ['front:system:page:show']
Routes the editor may link to: text pages only.

Properties

$editorLinkPageManager  : PageManager
NOTE: own property name. `$pageManager` already exists on presenters (`PagePickerTrait`), and two `#[Inject]` properties of the same name would collide in the trait composition.

Methods

handleEditorPages()  : void
Sends the page list for the link dialog as JSON `{"pages": [{id, label, url}, ...]}` sorted by label.
editorLinkLangId()  : int
Returns the language used to pick labels and URLs (default 1, Czech).
editorPageLabel()  : string
Returns the page label: title, otherwise name, otherwise `#id`.
editorPageRoute()  : Route|null
Returns the first page route the editor may link to. A page may have several (many-to-many); the whitelisted one is taken, not the first in order, so a page with both `Page:show` and `Page:form` ends up on the right one.
editorPageUrl()  : string|null
Returns the front end address of a page. The router builds it from the page route, so `/o-nas` and any prefix come out on their own.

Constants

EDITOR_PAGE_LIMIT

Listing cap; the dialog is a suggester, not a paged list.

private mixed EDITOR_PAGE_LIMIT = 500

EDITOR_PAGE_TARGETS

Routes the editor may link to: text pages only.

private mixed EDITOR_PAGE_TARGETS = ['front:system:page:show']

Other page routes need parameters the editor cannot know (Front:System:User:profile wants id and username, Front:System:Registration:registration wants email and activationKey, advert details want id/name). A link to them could not be built or would lead to a broken address, so they stay out of the offer.

Another target (e.g. Front:System:Page:homepage or Front:System:Page:form) is one more line here, provided its route needs only slug.

Properties

$editorLinkPageManager

NOTE: own property name. `$pageManager` already exists on presenters (`PagePickerTrait`), and two `#[Inject]` properties of the same name would collide in the trait composition.

public PageManager $editorLinkPageManager
Attributes
#[Inject]

Methods

handleEditorPages()

Sends the page list for the link dialog as JSON `{"pages": [{id, label, url}, ...]}` sorted by label.

public handleEditorPages() : void

Only text pages (EDITOR_PAGE_TARGETS); pages without a filled URL (href) are skipped too, because no link can be built for them.

editorLinkLangId()

Returns the language used to pick labels and URLs (default 1, Czech).

private editorLinkLangId() : int
Return values
int

editorPageLabel()

Returns the page label: title, otherwise name, otherwise `#id`.

private editorPageLabel(Page $page, int $langId) : string
Parameters
$page : Page
$langId : int
Return values
string

editorPageRoute()

Returns the first page route the editor may link to. A page may have several (many-to-many); the whitelisted one is taken, not the first in order, so a page with both `Page:show` and `Page:form` ends up on the right one.

private editorPageRoute(Page $page) : Route|null
Parameters
$page : Page
Return values
Route|null

editorPageUrl()

Returns the front end address of a page. The router builds it from the page route, so `/o-nas` and any prefix come out on their own.

private editorPageUrl(Page $page, int $langId) : string|null
Parameters
$page : Page
$langId : int
Return values
string|null —

null when the page is not a text page (see EDITOR_PAGE_TARGETS), has no filled URL, or its route cannot build a link

On this page

Search results