CoolCMS API

MessageFormTrait

Add/edit form of a discussion message: the Front `MessageFormComponent` fields (username, e-mail, subject, text, `externalUrl`, `showComments`, categories, images) plus admin moderation, the parent (tree) and topping.

The skeleton (checks, domain translator, save/update/cancel buttons, return to the previous page) comes from BasePresenter::createForm(). The parent (single) and the categories (many-to-many, in a Multiplier) are edited with pickers; the author (userId) uses the User picker. Images go to the Api in meta['orderedAssets'] (new images as a path into the dropzone temp directory, existing ones by id); the Api afterSave stores the variants, the Asset and the link. Comments and ratings are edited in their own tabs, not here.

Table of Contents

Constants

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

Methods

createComponentEditForm()  : Form
addAuthorFields()  : void
Adds the author and tree placement: hidden picker fields (the picker component renders the UI).
addCategoryMultiplier()  : void
Adds the category multiplier (many-to-many via picker; a row is a hidden `categoryId` plus a label).
addContentFields()  : void
Adds the message content: subject, text (reduced TinyMCE as on the front end), external link, topping.
addImageFields()  : void
Wires the images to the dropzone uploader (the `uploader` component, same as the Front).
addModerationFields()  : void
Adds the moderation flags of the message.
applyCategories()  : void
Rewrites the many-to-many category link from the picker rows (object-graph save: the Api hydrator resolves the managed references and synchronizes the join table).
buildCategoryRowDefaults()  : array<int, array{categoryId: int, category: string}>
Maps categories to picker rows (hidden id and a label with the name in the current language).
buildMessageEntity()  : Message
collectOrderedAssets()  : array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>
Builds `meta['orderedAssets']` for the Api `afterSave` from the ordered dropzone list (`uploaderItems[]` from the POST).
fetchCategories()  : array<int, Category>
Loads categories by id (managed references for the many-to-many write).
rowIds()  : array<int, int>
Collects unique positive ids from the multiplier rows (each row is a hidden `<field>`).
saveMessageForm()  : bool
Saves the form data; the redirect comes from {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
setMessageFormDefaults()  : void
str()  : string
Safely converts a mixed form value to string.
strOrNull()  : string|null
Safely converts a mixed value to string|null (an empty string becomes null).

Constants

MSG_DT_FORMAT

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

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

Methods

addAuthorFields()

Adds the author and tree placement: hidden picker fields (the picker component renders the UI).

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

addCategoryMultiplier()

Adds the category multiplier (many-to-many via picker; a row is a hidden `categoryId` plus a label).

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

addContentFields()

Adds the message content: subject, text (reduced TinyMCE as on the front end), external link, topping.

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

addImageFields()

Wires the images to the dropzone uploader (the `uploader` component, same as the Front).

private addImageFields(Form $form) : void

The form carries only the hidden dropzoneToken (identifies the temp directory); the component holds the selected files (AJAX upload to temp) and the ordered list (existing plus new) arrives in the POST as uploaderItems[]. On a re-render after a validation error the token is recovered from the POST.

Parameters
$form : Form

addModerationFields()

Adds the moderation flags of the message.

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

applyCategories()

Rewrites the many-to-many category link from the picker rows (object-graph save: the Api hydrator resolves the managed references and synchronizes the join table).

private applyCategories(Message $message, ArrayHash<string|int, mixed> $values) : void
Parameters
$message : Message
$values : ArrayHash<string|int, mixed>

buildCategoryRowDefaults()

Maps categories to picker rows (hidden id and a label with the name in the current language).

private buildCategoryRowDefaults(Message $message) : array<int, array{categoryId: int, category: string}>
Parameters
$message : Message
Return values
array<int, array{categoryId: int, category: string}>

buildMessageEntity()

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

collectOrderedAssets()

Builds `meta['orderedAssets']` for the Api `afterSave` from the ordered dropzone list (`uploaderItems[]` from the POST).

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

existing is the id of an existing image, dropzone is a newly uploaded file in the temp directory (its path is looked up by name). The order is the sequence; the first is the main image. Mirrors the dropzone branch of Front MessageForm::onSuccess().

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

fetchCategories()

Loads 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>

rowIds()

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

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

saveMessageForm()

Saves the form data; the redirect comes from {@see \App\Core\Base\Admin\BasePresenter::createForm()}.

private saveMessageForm(ArrayHash<string|int, mixed> $values) : bool

Images go to the Api in meta['orderedAssets'] (afterSave). A parent change is passed in meta['moveSubtreeToParentId'] so the lft / rgt / level recalculation of the subtree runs in the same transaction as the save, as for Page.

Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

str()

Safely converts a mixed form value to string.

private str(mixed $value) : string
Parameters
$value : mixed
Return values
string

strOrNull()

Safely converts a mixed value to string|null (an empty string becomes null).

private strOrNull(mixed $value) : string|null
Parameters
$value : mixed
Return values
string|null
On this page

Search results