CoolCMS API

AdvertAssetTrait

Advert-specific hooks for `AssetProcessingTrait` plus processing of file attachments.

Asset processing (image variants, watermark, relations) comes from the shared AssetProcessingTrait; this trait holds only the advert bindings (subDir, dir keys, variant type, rel factory).

Tags
requires

AdvertManager expects:

  • getSettings() (SettingsTrait)
  • $variantProvider (AssetVariantProvider)
  • $assetManager / $fileManager
  • updateColumn / updateAllRelations (SaveTrait)

Table of Contents

Methods

createAssetRel()  : object
getAssetDirAbs()  : string
getAssetDirRel()  : string
getAssetSubDir()  : string
getAssetVariantType()  : string
guardNewFiles()  : Result|null
Gate for new attachments, called from `beforeSave()`, before the advert and files are written.
processFiles()  : Result|null
Processes the ordered file list (existing and new in one array).

Methods

createAssetRel()

protected createAssetRel(object $parent, Asset $asset, int $order, bool $isMain) : object
Parameters
$parent : object
$asset : Asset
$order : int
$isMain : bool
Return values
object

getAssetDirAbs()

protected getAssetDirAbs() : string
Return values
string

getAssetDirRel()

protected getAssetDirRel() : string
Return values
string

getAssetSubDir()

protected getAssetSubDir(int $parentId) : string
Parameters
$parentId : int
Return values
string

getAssetVariantType()

protected getAssetVariantType() : string
Return values
string

guardNewFiles()

Gate for new attachments, called from `beforeSave()`, before the advert and files are written.

private guardNewFiles(array<string, mixed> $meta) : Result|null

One forbidden file rejects the whole save (the user would not notice a silently dropped file). The rule is held by AttachmentFilePolicy; the dropzone is only UX, external clients call the API too.

Parameters
$meta : array<string, mixed>
Return values
Result|null

processFiles()

Processes the ordered file list (existing and new in one array).

private processFiles(Advert &$entity, array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}> $orderedFiles) : Result|null

Each item is {type: 'existing', fileId, order} or {type: 'new', name, data|path, order} (path = a file in the dropzone temp folder, internal calls only).

Parameters
$entity : Advert
$orderedFiles : array<int, array{type: string, fileId?: int, name?: string, data?: string, path?: string, order?: int}>
Return values
Result|null
On this page

Search results