CoolCMS API

FormTrait

Form for the written review in a modal (`MODE_REVIEW`).

Requires in the host class:

  • $this->ratingManager, $this->threadId, $this->translator, $this->translatorDomain
  • getModalTarget(), createModalContent(), createSuccessContent(), createModalEvent()
  • buildRating(int $value) (HandleTrait), canVote(), initializeRender()

Table of Contents

Constants

PROS_CONS_MAX_ITEMS  : mixed = 10
Max count and length of pros/cons items (server-side sanitization).
PROS_CONS_MAX_LENGTH  : mixed = 120

Methods

createComponentReplyForm()  : Form
Review reply form (in a modal): textarea and submit.
createComponentReviewForm()  : Form
Written review form (in a modal): stars, text, pros and cons.
onReviewError()  : void
Re-renders the modal with errors when validation fails (no stars, forged value).
onSubmit()  : void
Handles the review submission.
onSubmitReply()  : void
Handles the review reply submission.
decodeItems()  : array<int, string>|null
Decodes and sanitizes a JSON array of strings from a hidden input (pros/cons).
handleSubmitError()  : void
Handles a submission error. `$resultKey` selects the translation key under `.result.*` (`duplicated` for the dedup rejection from {@see \App\UI\Api\Base\Models\Managers\RatingManager::beforeSave()}, otherwise the generic `failure`), so the user sees "already rated" instead of a generic error.
handleSubmitSuccess()  : void
Handles a successful submission.
normalizeText()  : string|null
Returns null for empty text (stars only), otherwise the trimmed text.
resolveSubmittedThreadId()  : int
Returns the thread for writing a review. A component with a server-set thread (`setThreadId()` in the parent) always uses that one; any other hidden-field value yields 0, so `canVote()` rejects the write. Without a set thread nothing is written.
updateModalContent()  : void
Aktualizuje obsah modalu

Constants

PROS_CONS_MAX_ITEMS

Max count and length of pros/cons items (server-side sanitization).

private mixed PROS_CONS_MAX_ITEMS = 10

PROS_CONS_MAX_LENGTH

private mixed PROS_CONS_MAX_LENGTH = 120

Methods

createComponentReplyForm()

Review reply form (in a modal): textarea and submit.

public createComponentReplyForm() : Form
Return values
Form

createComponentReviewForm()

Written review form (in a modal): stars, text, pros and cons.

public createComponentReviewForm() : Form
Return values
Form

onReviewError()

Re-renders the modal with errors when validation fails (no stars, forged value).

public onReviewError(Form $form) : void

IMPORTANT: without this handler an invalid submit (client validation bypassed or off) was rejected by the server and nothing happened in the modal, leaving the user with no hint why.

Parameters
$form : Form

onSubmit()

Handles the review submission.

public onSubmit(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

onSubmitReply()

Handles the review reply submission.

public onSubmitReply(Form $form, ArrayHash $values) : void
Parameters
$form : Form
$values : ArrayHash

decodeItems()

Decodes and sanitizes a JSON array of strings from a hidden input (pros/cons).

private decodeItems(string|null $json) : array<int, string>|null
Parameters
$json : string|null
Return values
array<int, string>|null

handleSubmitError()

Handles a submission error. `$resultKey` selects the translation key under `.result.*` (`duplicated` for the dedup rejection from {@see \App\UI\Api\Base\Models\Managers\RatingManager::beforeSave()}, otherwise the generic `failure`), so the user sees "already rated" instead of a generic error.

private handleSubmitError(Form $form[, string $resultKey = 'result.failure' ]) : void
Parameters
$form : Form
$resultKey : string = 'result.failure'

handleSubmitSuccess()

Handles a successful submission.

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

normalizeText()

Returns null for empty text (stars only), otherwise the trimmed text.

private normalizeText(string|null $text) : string|null
Parameters
$text : string|null
Return values
string|null

resolveSubmittedThreadId()

Returns the thread for writing a review. A component with a server-set thread (`setThreadId()` in the parent) always uses that one; any other hidden-field value yields 0, so `canVote()` rejects the write. Without a set thread nothing is written.

private resolveSubmittedThreadId(mixed $submitted) : int
Parameters
$submitted : mixed
Return values
int

updateModalContent()

Aktualizuje obsah modalu

private updateModalContent(string $content) : void
Parameters
$content : string
On this page

Search results