AdvertUploaderTrait
Configures the shared `UploaderDropzone` components for the company profile image and file uploader parameters.
imgUploader handles images (assetRels) and fileUploader handles files (fileRels);
each is a separate child with its own temp directory. The Api afterSave hook writes
the result from meta['assets'] / meta['files'].
Table of Contents
Methods
- getUploaderControlMap() : array<string, string>
- Returns the map of form control name to uploader child name.
- createComponentFileUploader() : UploaderDropzone
- createComponentImgUploader() : UploaderDropzone
- addUploaderFields() : void
- Adds 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` hook.
- buildFilesMeta() : array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|null
- Builds `meta['files']` for the Api `afterSave` hook (`processFiles()` writes `fileRels`).
- cleanupUploaders() : void
- configureFileUploader() : void
- configureImageUploader() : void
- Configures the uploader; runs from its factory, not from `prepareParameterForm()`.
- 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 existing files for the dropzone (the `imageId` key is the dropzone's generic identifier).
- resolveUploaderToken() : string|null
- syncUploaderTokenFields() : void
- Syncs the hidden token fields with the real uploader temp directories.
Methods
getUploaderControlMap()
Returns the map of form control name to uploader child name.
public
getUploaderControlMap() : array<string, string>
The first image uploader parameter maps to imgUploader, the first file uploader parameter
to fileUploader. The template looks controls up here and renders a dropzone where an entry
exists (otherwise a classic input).
Return values
array<string, string>createComponentFileUploader()
protected
createComponentFileUploader() : UploaderDropzone
Return values
UploaderDropzonecreateComponentImgUploader()
protected
createComponentImgUploader() : UploaderDropzone
Return values
UploaderDropzoneaddUploaderFields()
Adds hidden fields with the dropzone temp directory tokens.
private
addUploaderFields(Form $form) : void
On an AJAX re-render (validation error) the token is looked up from the POST. Called from AdvertFormTrait::createComponentEditForm().
Parameters
- $form : Form
buildAssetsMeta()
Builds `meta['assets']` for the Api `afterSave` hook.
private
buildAssetsMeta(ArrayHash $values) : array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>|null
The ordered list holds existing image ids and new files as a path reference into the temp directory.
IMPORTANT: an empty list is a legitimate 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 put the assets key into 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}>|nullbuildFilesMeta()
Builds `meta['files']` for the Api `afterSave` hook (`processFiles()` writes `fileRels`).
private
buildFilesMeta(ArrayHash $values) : array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|null
Same structure as the assets list, with fileId instead of imageId. 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 put into meta.
Parameters
- $values : ArrayHash
Return values
array<int, array{type: string, fileId?: int, name?: string, path?: string, order: int}>|nullcleanupUploaders()
private
cleanupUploaders() : void
configureFileUploader()
private
configureFileUploader(UploaderDropzone $uploader) : void
Parameters
- $uploader : UploaderDropzone
configureImageUploader()
Configures the uploader; runs from its factory, not from `prepareParameterForm()`.
private
configureImageUploader(UploaderDropzone $uploader) : void
The dropzone upload signal is a separate request where the edit form is never built, so
configuring elsewhere would create the uploader with default directory and mime types and
the upload would fail. Takes the instance instead of $this[...] to avoid recursion in the factory.
Parameters
- $uploader : UploaderDropzone
findFirstParameterOfType()
private
findFirstParameterOfType(int $type) : Parameter|null
Parameters
- $type : int
Return values
Parameter|nullparseFileTypes()
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 existing files for the dropzone (the `imageId` key is the dropzone's generic 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|nullsyncUploaderTokenFields()
Syncs 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 the posted value
wins on a submitted form; on the add form it is empty because the uploaders did not exist
at submit time. The hidden field would render empty and buildAssetsMeta() would not know
which temp directory to take the uploaded files from.
Parameters
- $form : Form