CoolCMS API

ImageFormTrait

Add/edit form of an image (Asset).

Multilingual fields (name, description, active translation) go to AssetText; the file input with preview is ImageUploadComponentTrait. The skeleton comes from BasePresenter::createForm().

Variants are not entered here. Uploading a new file uses the system-images usage plan (Settings, Image variants, Usage) supplied by the Api (ImageManager). Editing shows a read-only overview of the variants the image has (getImageVariantOverview()).

IMPORTANT: the form must not send variants. Otherwise the admin save would overwrite the variant record of an existing image (a save without a new file leaves the record unchanged).

Table of Contents

Methods

createComponentEditForm()  : Form
getImageVariantOverview()  : array<int, array{folder: string, variant: ?string, size: ?string, original: bool}>
Returns a read-only overview of the image variants (folder, variant, actual size) for the template.
addImageTranslationFields()  : void
Per-language fields: active translation, name, description (one set per language).
buildImageEntity()  : Asset
collectImageMeta()  : array<string, mixed>
Builds `$meta['image']` (base64) for the Api when a new file is uploaded.
saveImageForm()  : bool
setImageFormDefaults()  : void

Methods

getImageVariantOverview()

Returns a read-only overview of the image variants (folder, variant, actual size) for the template.

protected getImageVariantOverview() : array<int, array{folder: string, variant: ?string, size: ?string, original: bool}>
Return values
array<int, array{folder: string, variant: ?string, size: ?string, original: bool}>

addImageTranslationFields()

Per-language fields: active translation, name, description (one set per language).

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

buildImageEntity()

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

collectImageMeta()

Builds `$meta['image']` (base64) for the Api when a new file is uploaded.

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

saveImageForm()

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

Search results