CoolCMS API

PagePickerTrait

Front end page picker: the model of a reusable picker trait. A presenter uses it and calls {@see pagePicker()} in `pickers()`; the trait brings its own manager (`#[Inject]`), so it works in any presenter without further configuration.

Usage (self-reference too, e.g. a parent page):

protected function pickers(): array
{
    return ['parentId' => $this->pagePicker('editForm', 'parentId')];
}
Tags
see
UserPickerTrait

same pattern for users

Table of Contents

Properties

$pageManager  : PageManager

Methods

addPageControls()  : void
Adds the page picker controls (hidden id plus text label) to a multiplier row.
pageMultiplierPicker()  : PickerConfig
Page picker for a multiplier (several pages in one form, e.g. targeting an advert at specific pages). Unlike {@see pagePicker()}, it addresses the hidden field inside the multiplier container and carries a text `displayField`, so the label survives the AJAX re-render of the row. The row is built by {@see addPageControls()}.
pagePicker()  : PickerConfig
pageLabel()  : string
pickerLangId()  : int
resolvePageLabel()  : string|null
Label to prefill on edit (from the hidden value).
suggestPages()  : array<int, array{id: int, label: string}>
Suggestions: `OR LIKE` over the page name and title, optionally without the excluded node and its whole subtree (a page must not be its own parent or the parent of its descendant).

Properties

Methods

addPageControls()

Adds the page picker controls (hidden id plus text label) to a multiplier row.

protected addPageControls(Container $parent[, string $targetField = 'pageId' ][, string $displayField = 'page' ]) : void
Parameters
$parent : Container
$targetField : string = 'pageId'
$displayField : string = 'page'

pageMultiplierPicker()

Page picker for a multiplier (several pages in one form, e.g. targeting an advert at specific pages). Unlike {@see pagePicker()}, it addresses the hidden field inside the multiplier container and carries a text `displayField`, so the label survives the AJAX re-render of the row. The row is built by {@see addPageControls()}.

protected pageMultiplierPicker([string $formName = 'editForm' ][, string $container = 'pages' ][, string $targetField = 'pageId' ][, string $displayField = 'page' ]) : PickerConfig
Parameters
$formName : string = 'editForm'

form name (editForm)

$container : string = 'pages'

name of the multiplier container (pages)

$targetField : string = 'pageId'

name of the hidden control in the row (pageId)

$displayField : string = 'page'

name of the text label control in the row (page)

Return values
PickerConfig

pagePicker()

protected pagePicker(string $formName, string $targetField[, int|null $excludeId = null ][, int|null $excludeSubtreeLft = null ][, int|null $excludeSubtreeRgt = null ]) : PickerConfig
Parameters
$formName : string

form name with the hidden field (editForm)

$targetField : string

name of the hidden control (parentId)

$excludeId : int|null = null

id that must not be selected (self-reference); excluded from the suggestions and the modal (passed to the show grid via pickerExclude)

$excludeSubtreeLft : int|null = null

lft of the edited node, to exclude the whole subtree

$excludeSubtreeRgt : int|null = null

rgt of the edited node, to exclude the whole subtree

Return values
PickerConfig

pageLabel()

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

resolvePageLabel()

Label to prefill on edit (from the hidden value).

private resolvePageLabel(int $id) : string|null
Parameters
$id : int
Return values
string|null

suggestPages()

Suggestions: `OR LIKE` over the page name and title, optionally without the excluded node and its whole subtree (a page must not be its own parent or the parent of its descendant).

private suggestPages(string $query[, int|null $excludeId = null ][, int|null $excludeSubtreeLft = null ][, int|null $excludeSubtreeRgt = null ]) : array<int, array{id: int, label: string}>
Parameters
$query : string
$excludeId : int|null = null
$excludeSubtreeLft : int|null = null
$excludeSubtreeRgt : int|null = null
Return values
array<int, array{id: int, label: string}>
On this page

Search results