CoolCMS API

GalleryFormTrait

Edit/add form of a blog gallery.

Multilingual fields (name, description); untranslated: visible only to logged-in users and category assignment (many-to-many via picker in a multiplier).

Gallery images are managed by a multiplier (row = image upload + its per-language title/description translations). Each image is a System Asset with its own translations (AssetText); the gallery is linked to images by a pure many-to-many (cms_mod_blog_gallery_image_relations). The new image bytes and translations go to the Api in $meta['images']; variants, the Asset entity, AssetText and the many-to-many link are saved by GalleryManager in afterSave.

The skeleton comes from BasePresenter::createForm().

Table of Contents

Constants

GALLERY_DT_FORMAT  : mixed = 'Y-m-d\TH:i'
Value format of `<input type=datetime-local>`.

Methods

createComponentEditForm()  : Form
addCategoryMultiplier()  : void
Category multiplier (many-to-many via picker; row = hidden `categoryId` + label).
addImageMultiplier()  : void
Gallery image multiplier: row = upload + hidden `imageCurrentId`/`imageUrl` (preview) + per-language title/description.
addImageRowControls()  : void
Fields of one image row: upload, preview and per-language title/description.
addSettingsFields()  : void
Untranslated fields: publish date, activation, visibility and category assignment.
addTranslationFields()  : void
Multilingual fields: one set per language (`<field>_<langId>`), active according to the checkbox.
buildGalleryEntity()  : Gallery
buildImageRowDefaults()  : array<int, array<string, mixed>>
Image rows for the multiplier when editing, from `assetRels` (via `getAssets()`, sorted by `order`). The preview is the thumbnail variant of the image.
collectImageMeta()  : array<int, array{assetId: int, image: array{name: string, data: string}|null, texts: array}>
Builds `$meta['images']` for the Api `afterSave`: an ordered list of image rows: - `assetId` = id of the existing image (0 = new upload), - `image` = ['name','data' (base64)] of the new image (null = file unchanged), - `texts[<langId>]` = ['title','description'] (per-language translation of the image).
fetchCategories()  : array<int, Category>
Resolves categories by id (managed references for the many-to-many write).
findAssetText()  : AssetText|null
Finds the image translation for the given language (null when none).
rowIds()  : array<int, int>
Collects unique positive ids from the multiplier rows (each row has a hidden `<field>`).
saveGalleryForm()  : bool
setGalleryFormDefaults()  : void

Constants

Value format of `<input type=datetime-local>`.

private mixed GALLERY_DT_FORMAT = 'Y-m-d\TH:i'

Methods

addCategoryMultiplier()

Category multiplier (many-to-many via picker; row = hidden `categoryId` + label).

private addCategoryMultiplier(Form $form) : void
Parameters
$form : Form

addImageMultiplier()

Gallery image multiplier: row = upload + hidden `imageCurrentId`/`imageUrl` (preview) + per-language title/description.

private addImageMultiplier(Form $form) : void

Rows are added and removed purely client-side (generic client-multiplier.js, opt-in [data-multiplier] in the template): clone of a <template> plus DOM removal, without a naja redraw. Any snippet re-render would wipe already chosen <input type=file> values (browsers cannot refill them programmatically), so this server-side Multiplier has no add/remove buttons and serves only as a container: on submit it creates a container for every posted index (ComponentResolver keeps keys via array_slice(..., true), so gaps in the indexes after a row removal do no harm; order = DOM sequence in the POST).

Parameters
$form : Form

addImageRowControls()

Fields of one image row: upload, preview and per-language title/description.

private addImageRowControls(Container $container) : void
Parameters
$container : Container

addSettingsFields()

Untranslated fields: publish date, activation, visibility and category assignment.

private addSettingsFields(Form $form) : void
Parameters
$form : Form

addTranslationFields()

Multilingual fields: one set per language (`<field>_<langId>`), active according to the checkbox.

private addTranslationFields(Form $form) : void
Parameters
$form : Form

buildGalleryEntity()

private buildGalleryEntity(ArrayHash<string|int, mixed> $values) : Gallery
Parameters
$values : ArrayHash<string|int, mixed>
Return values
Gallery

buildImageRowDefaults()

Image rows for the multiplier when editing, from `assetRels` (via `getAssets()`, sorted by `order`). The preview is the thumbnail variant of the image.

private buildImageRowDefaults(Gallery $gallery) : array<int, array<string, mixed>>
Parameters
$gallery : Gallery
Return values
array<int, array<string, mixed>>

collectImageMeta()

Builds `$meta['images']` for the Api `afterSave`: an ordered list of image rows: - `assetId` = id of the existing image (0 = new upload), - `image` = ['name','data' (base64)] of the new image (null = file unchanged), - `texts[<langId>]` = ['title','description'] (per-language translation of the image).

private collectImageMeta(ArrayHash<string|int, mixed> $values) : array<int, array{assetId: int, image: array{name: string, data: string}|null, texts: array}>

Empty rows (no assetId and no upload) are skipped. An empty array is returned too, so the Api knows to synchronize the collection (including emptying it).

Parameters
$values : ArrayHash<string|int, mixed>
Return values
array<int, array{assetId: int, image: array{name: string, data: string}|null, texts: array}>

fetchCategories()

Resolves categories by id (managed references for the many-to-many write).

private fetchCategories(array<int, int> $ids) : array<int, Category>
Parameters
$ids : array<int, int>
Return values
array<int, Category>

findAssetText()

Finds the image translation for the given language (null when none).

private findAssetText(Asset $asset, int $langId) : AssetText|null
Parameters
$asset : Asset
$langId : int
Return values
AssetText|null

rowIds()

Collects unique positive ids from the multiplier rows (each row has a hidden `<field>`).

private rowIds(mixed $rows, string $field) : array<int, int>
Parameters
$rows : mixed
$field : string
Return values
array<int, int>

saveGalleryForm()

private saveGalleryForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool
On this page

Search results