CoolCMS API

CustomAssetTabSaveTrait

Decision logic for saving the custom code tab of the page form.

Kept apart from the presenter (no translator or flash) so it can be tested without a DB or network by overriding the seams savePageEntity(), syncPageCustomAssets() and deletePageNode().

IMPORTANT: this is not one transaction and cannot be in this architecture. Saving the page (api/system/page/save) and the code set (api/system/custom-asset/sync-page) are two separate Api operations over the bridge, each with its own DB transaction. Safeguards:

  1. a preflight check of the asset ids (CustomAssetPayload::normalizeIds()) before the page is saved, so an invalid id never touches the page;
  2. compensation for a new page: when the set fails in the DB, the just created page is deleted (deleteNode()) and nothing remains. An existing page gets no compensation, because restoring its fields would be a second write that can fail like the first.

Requires $this->pageManager and $this->customAssetManager in the host (PagePresenter injects them through its constructor).

Table of Contents

Methods

extractCustomAssetRowIds()  : array<int, mixed>
Returns the ids from the tab rows (hidden `assetId`).
persistPageCustomAssetsTab()  : CustomAssetTabSaveOutcome
deletePageNode()  : Result
Seam: compensation for a new page.
savePageEntity()  : Result
Seam: saves the page entity. Override in a test to avoid touching the DB.
syncPageCustomAssets()  : Result
Seam: syncs the page code set (`api/system/custom-asset/sync-page`).

Methods

extractCustomAssetRowIds()

Returns the ids from the tab rows (hidden `assetId`).

public extractCustomAssetRowIds(iterable<string|int, mixed> $rows) : array<int, mixed>

Empty rows (added by the user with nothing selected) are skipped so they never reach the normalizer.

Parameters
$rows : iterable<string|int, mixed>
Return values
array<int, mixed>

persistPageCustomAssetsTab()

public persistPageCustomAssetsTab(bool $mayAssign, array<int, mixed> $rawAssetIds, Page $page, array<string, mixed> $meta, bool $isInsert) : CustomAssetTabSaveOutcome
Parameters
$mayAssign : bool
$rawAssetIds : array<int, mixed>

raw id values from the tab rows (non-empty rows only, see extractCustomAssetRowIds()), ignored entirely when $mayAssign is false

$page : Page
$meta : array<string, mixed>

meta for pageManager->save() (e.g. moveSubtreeToParentId)

$isInsert : bool
Return values
CustomAssetTabSaveOutcome

savePageEntity()

Seam: saves the page entity. Override in a test to avoid touching the DB.

protected savePageEntity(Page $page, array<string, mixed> $meta) : Result
Parameters
$page : Page
$meta : array<string, mixed>
Return values
Result

syncPageCustomAssets()

Seam: syncs the page code set (`api/system/custom-asset/sync-page`).

protected syncPageCustomAssets(int $pageId, array<int, int> $assetIds) : Result
Parameters
$pageId : int
$assetIds : array<int, int>
Return values
Result
On this page

Search results