CoolCMS API

CustomAssetTabTrait

Custom code tab of the page form; it only assigns existing codes to the page.

Codes are created and edited solely in the library (Admin:System:CustomAsset). A row is a picker (CustomAssetPickerTrait) plus a read-only type and placement filled in from customAssetLookupMap().

IMPORTANT: privileges. show makes the tab exist (read-only); assign allows changing the set. The multiplier and picker are added to the form only with assign; without it the form has no such fields, so nothing can be submitted. Without show the tab is not added at all (see PagePresenter::addCustomAssetFields()).

Requires $this->customAssetManager (CustomAssetManager) and the method CustomAssetPickerTrait::addCustomAssetPickerControls() in the host.

Table of Contents

Properties

$customAssetRowsCache  : array<int, CustomAsset>|null
Assets loaded for the current page and mode, cached per request (one presenter instance per request), so defaults and the lookup map share one DB query.

Methods

addCustomAssetTab()  : void
Adds the `customAssets` multiplier to the form, only with the `assign` privilege.
customAssetLookupMap()  : array<int, array{type: string, placement: string}>
Returns an id to type and placement map only for assets loaded in this request (the tab defaults). A newly selected row (id outside this set) keeps type and placement empty in the template until the page is reloaded.
loadCustomAssetReadOnlyRows()  : array<int, array{id: int, name: string, type: string, placement: string}>
Returns the rows for the read-only display (without `assign`), passed straight to the template because the form field does not exist without the privilege.
loadCustomAssetTabDefaults()  : array<int, array{assetId: string, asset: string}>
Returns the multiplier defaults: the codes assigned to the page when editing, the codes with `addToNewPages = 1` when adding.
mayAssignCustomAssets()  : bool
Whether the user may change the set (picker, add, remove).
mayEditCustomAssetInLibrary()  : bool
Whether the user may open a code for editing in the library (the edit link).
mayShowCustomAssets()  : bool
Whether the user may see the tab at all (read-only included).
customAssetPickerLabelFor()  : string
customAssetPlacementLabel()  : string
customAssetTypeLabel()  : string
loadCustomAssetTabEntities()  : array<int, CustomAsset>
Loads the assets relevant to `$page` in one query, shared by defaults, the lookup map and the read-only list (cached on the presenter instance).
redrawCustomAssetTab()  : void
Redraws the tab rows.
trCustomAssetTabKey()  : string
Translates an absolute key shared with the library (`CustomAssetFormTrait`), not duplicated.

Properties

$customAssetRowsCache

Assets loaded for the current page and mode, cached per request (one presenter instance per request), so defaults and the lookup map share one DB query.

private array<int, CustomAsset>|null $customAssetRowsCache = null

Methods

addCustomAssetTab()

Adds the `customAssets` multiplier to the form, only with the `assign` privilege.

protected addCustomAssetTab(Form $form) : void

Without it the form has no such field: the template skips it by isset() and saving the page does not save the set, see CustomAssetTabSaveTrait.

Parameters
$form : Form

customAssetLookupMap()

Returns an id to type and placement map only for assets loaded in this request (the tab defaults). A newly selected row (id outside this set) keeps type and placement empty in the template until the page is reloaded.

protected customAssetLookupMap(Page|null $page) : array<int, array{type: string, placement: string}>
Parameters
$page : Page|null
Return values
array<int, array{type: string, placement: string}>

loadCustomAssetReadOnlyRows()

Returns the rows for the read-only display (without `assign`), passed straight to the template because the form field does not exist without the privilege.

protected loadCustomAssetReadOnlyRows(Page|null $page) : array<int, array{id: int, name: string, type: string, placement: string}>
Parameters
$page : Page|null
Return values
array<int, array{id: int, name: string, type: string, placement: string}>

loadCustomAssetTabDefaults()

Returns the multiplier defaults: the codes assigned to the page when editing, the codes with `addToNewPages = 1` when adding.

protected loadCustomAssetTabDefaults(Page|null $page) : array<int, array{assetId: string, asset: string}>
Parameters
$page : Page|null
Return values
array<int, array{assetId: string, asset: string}>

mayAssignCustomAssets()

Whether the user may change the set (picker, add, remove).

protected mayAssignCustomAssets() : bool
Return values
bool

mayEditCustomAssetInLibrary()

Whether the user may open a code for editing in the library (the edit link).

protected mayEditCustomAssetInLibrary() : bool
Return values
bool

mayShowCustomAssets()

Whether the user may see the tab at all (read-only included).

protected mayShowCustomAssets() : bool
Return values
bool

loadCustomAssetTabEntities()

Loads the assets relevant to `$page` in one query, shared by defaults, the lookup map and the read-only list (cached on the presenter instance).

private loadCustomAssetTabEntities(Page|null $page) : array<int, CustomAsset>
Parameters
$page : Page|null
Return values
array<int, CustomAsset>

redrawCustomAssetTab()

Redraws the tab rows.

private redrawCustomAssetTab() : void

The customAssets snippet lives in an included template (Page/parts/custom-assets.latte), so the wrapping {snippetArea customAssetsArea} in Page/edit.latte must be redrawn too; otherwise Latte does not find the snippet in the AJAX response and the added row silently does not appear.

trCustomAssetTabKey()

Translates an absolute key shared with the library (`CustomAssetFormTrait`), not duplicated.

private trCustomAssetTabKey(string $key) : string
Parameters
$key : string
Return values
string
On this page

Search results