CoolCMS API

AdvertUploaderTrait

Configures the shared `UploaderDropzone` components for the `IMAGE_UPLOADER` (`imgUploader`, images to `Asset`/`assetRels`) and `FILE_UPLOADER` (`fileUploader`, files to `File`/`fileRels`) advert parameters.

Each type has its own child with its own temp directory. The Api afterSave writes the result from meta['assets'] and meta['files'].

Table of Contents

Methods

getUploaderControlMap()  : array<string, string>
Returns the map of form control name to uploader child name: the first `IMAGE_UPLOADER` maps to `imgUploader`, the first `FILE_UPLOADER` to `fileUploader`. The template looks controls up here and renders a dropzone for a match, a classic input otherwise.
createComponentFileUploader()  : UploaderDropzone
createComponentImgUploader()  : UploaderDropzone
addUploaderFields()  : void
Adds the hidden fields with the dropzone temp-directory tokens.
buildAssetsMeta()  : array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>|null
Builds `meta['assets']` for the Api `afterSave`: the ordered images, existing ids plus new files as a `path` into the temp directory.
buildFilesMeta()  : array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|null
Builds `meta['files']` for the Api `afterSave` (`processFiles` to `fileRels`): the ordered files, existing ids plus new files as a `path` into the temp directory. Same shape as the assets, with `fileId` instead of `imageId`.
cleanupUploaders()  : void
configureFileUploader()  : void
configureImageUploader()  : void
Configures the image uploader.
findFirstParameterOfType()  : Parameter|null
parseFileTypes()  : array<string|int, string>
prepareExistingAssets()  : array<int, array{imageId: int, thumbPath: string, isMain: bool, order: int}>
prepareExistingFiles()  : array<int, array{imageId: int, thumbPath: string, fileName: string, isMain: bool, order: int}>
Returns the existing files for the dropzone (the key `imageId` is the generic dropzone identifier).
resolveUploaderToken()  : string|null
syncUploaderTokenFields()  : void
Aligns the hidden token fields with the real uploader temp directories.

Methods

getUploaderControlMap()

Returns the map of form control name to uploader child name: the first `IMAGE_UPLOADER` maps to `imgUploader`, the first `FILE_UPLOADER` to `fileUploader`. The template looks controls up here and renders a dropzone for a match, a classic input otherwise.

public getUploaderControlMap() : array<string, string>
Return values
array<string, string>

buildAssetsMeta()

Builds `meta['assets']` for the Api `afterSave`: the ordered images, existing ids plus new files as a `path` into the temp directory.

private buildAssetsMeta(ArrayHash $values) : array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>|null

IMPORTANT: an empty list is a valid instruction to remove all images (the user deleted the last one) and the caller must send it. "Unknown" (no uploader in the form) is returned as null and the caller must not set the assets key in meta; otherwise a missing component would delete the relations. Same tri-state pattern as ComplaintFileUploaderTrait::buildComplaintFilesMeta().

Parameters
$values : ArrayHash
Return values
array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>|null

buildFilesMeta()

Builds `meta['files']` for the Api `afterSave` (`processFiles` to `fileRels`): the ordered files, existing ids plus new files as a `path` into the temp directory. Same shape as the assets, with `fileId` instead of `imageId`.

private buildFilesMeta(ArrayHash $values) : array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|null

Same tri-state semantics as buildAssetsMeta(): an empty list removes all files, null means there is no uploader in the form and the files key must not be set in meta.

Parameters
$values : ArrayHash
Return values
array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|null

configureImageUploader()

Configures the image uploader.

private configureImageUploader(UploaderDropzone $uploader) : void

IMPORTANT: this runs in the component factory (createComponent*()), not in prepareParameterForm(). The dropzone upload signal is a separate request in which the edit form is never built, so the uploader would be created unconfigured (default subDir and mime types) and the upload would fail. It takes the instance instead of $this[...] to avoid recursion inside the factory.

Parameters
$uploader : UploaderDropzone

parseFileTypes()

private parseFileTypes(string|null $fileType, array<string|int, string> $fallback) : array<string|int, string>
Parameters
$fileType : string|null
$fallback : array<string|int, string>
Return values
array<string|int, string>

prepareExistingAssets()

private prepareExistingAssets() : array<int, array{imageId: int, thumbPath: string, isMain: bool, order: int}>
Return values
array<int, array{imageId: int, thumbPath: string, isMain: bool, order: int}>

prepareExistingFiles()

Returns the existing files for the dropzone (the key `imageId` is the generic dropzone identifier).

private prepareExistingFiles() : array<int, array{imageId: int, thumbPath: string, fileName: string, isMain: bool, order: int}>
Return values
array<int, array{imageId: int, thumbPath: string, fileName: string, isMain: bool, order: int}>

resolveUploaderToken()

private resolveUploaderToken(string $componentName, string $postField) : string|null
Parameters
$componentName : string
$postField : string
Return values
string|null

syncUploaderTokenFields()

Aligns the hidden token fields with the real uploader temp directories.

private syncUploaderTokenFields(Form $form) : void

Called from AJAX redraw handlers. addHidden() sets only a default and on a submitted form the POSTed value wins; on the add form it is empty because the uploaders did not exist at submit time. Without this the hidden field renders empty and buildAssetsMeta() cannot tell which temp directory holds the uploaded files on save.

Parameters
$form : Form
On this page

Search results