CoolCMS API

OperatorFormTrait

Form of the website operator: who runs the website, how to reach them and how they present themselves on the Operator card.

The web.operator.* keys (module 1) moved here from the generic site settings (SettingPresenter), where they were bare text fields named by the raw key. Here they have a label, a description and a section.

IMPORTANT: the photo follows the same path as the site identity logo: only the asset id is stored in the settings (SiteIdentityFormTrait), the image lives in cms_system_images. Replacing the photo edits the same asset; otherwise every replacement would leave an orphan row.

Table of Contents

Constants

OPERATOR_IMAGE_KEYS  : mixed = ['avatar' => 'web.operator.avatar.assetId']
Maps form fields to the setting key holding the asset id.
OPERATOR_MODULE  : mixed = 1
The operator settings live in the System module.
OPERATOR_TEXT_KEYS  : mixed = ['name' => 'web.operator.name', 'claim' => 'web...
Maps text form fields to setting keys.
OPERATOR_TEXTAREA_FIELDS  : mixed = ['perex', 'info']
Fields rendered as multiline (`addTextArea`); the rest are `addText`.

Properties

$imagePlanMissing  : bool
Set when the last failed image save was caused by the usage having no variant plan in the DB.

Methods

createComponentEditForm()  : Form
addOperatorImageFields()  : void
Operator photo or logo. `allowVector: true` because a company logo is often SVG and only an administrator uploads it (the Api sanitizes it on save).
addOperatorTextFields()  : void
Adds all text fields at once; label and description derive from the field name, so adding a key means adding a row to {@see OPERATOR_TEXT_KEYS} and a translation.
resolveOperatorAssetId()  : array{id: ?int, failed: bool, release?: ?int, created?: int}
Resolves the asset id to write to the settings for a field, in three states: `id` is what to store and `failed` means the image write failed.
saveOperatorAsset()  : int|null
Saves the uploaded file as an Asset and returns its id (null when the save failed).
saveOperatorForm()  : bool
setOperatorFormDefaults()  : void

Constants

OPERATOR_IMAGE_KEYS

Maps form fields to the setting key holding the asset id.

private mixed OPERATOR_IMAGE_KEYS = ['avatar' => 'web.operator.avatar.assetId']

A single image field, but kept as a map for symmetry with the rest (and because resolveOperatorAssetId() works with the field name, not the key).

OPERATOR_MODULE

The operator settings live in the System module.

private mixed OPERATOR_MODULE = 1

OPERATOR_TEXT_KEYS

Maps text form fields to setting keys.

private mixed OPERATOR_TEXT_KEYS = ['name' => 'web.operator.name', 'claim' => 'web.operator.claim', 'perex' => 'web.operator.perex', 'street' => 'web.operator.address.street', 'zip' => 'web.operator.address.zip', 'city' => 'web.operator.address.city', 'country' => 'web.operator.address.country', 'email' => 'web.operator.email', 'emailInfo' => 'web.operator.email.info', 'phone' => 'web.operator.phone', 'phoneInfo' => 'web.operator.phone.info', 'regNo' => 'web.operator.regNo', 'vatId' => 'web.operator.vatId', 'mapLatitude' => 'web.operator.map.latitude', 'mapLongitude' => 'web.operator.map.longitude', 'info' => 'web.operator.info']

The order is the field order in the template. claim and perex replace text that was hard-coded in the editorial card on the promo home page.

OPERATOR_TEXTAREA_FIELDS

Fields rendered as multiline (`addTextArea`); the rest are `addText`.

private mixed OPERATOR_TEXTAREA_FIELDS = ['perex', 'info']

Properties

$imagePlanMissing

Set when the last failed image save was caused by the usage having no variant plan in the DB.

private bool $imagePlanMissing = false

Methods

addOperatorImageFields()

Operator photo or logo. `allowVector: true` because a company logo is often SVG and only an administrator uploads it (the Api sanitizes it on save).

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

addOperatorTextFields()

Adds all text fields at once; label and description derive from the field name, so adding a key means adding a row to {@see OPERATOR_TEXT_KEYS} and a translation.

private addOperatorTextFields(Form $form) : void

IMPORTANT: name is the only required field. Without it the front card has nothing to show and the whole component silently renders nothing.

Parameters
$form : Form

resolveOperatorAssetId()

Resolves the asset id to write to the settings for a field, in three states: `id` is what to store and `failed` means the image write failed.

private resolveOperatorAssetId(string $field, ArrayHash<string|int, mixed> $values) : array{id: ?int, failed: bool, release?: ?int, created?: int}

Three paths: release (deletes the asset and the value), a new file (saved into the existing asset or a new one is created) and no change (<field>CurrentId is kept).

IMPORTANT: a bare null could not tell "admin asked to release" from "save failed", and a failed upload would empty …avatar.assetId and detach the current photo. On failure the original id is returned and the caller aborts the whole save.

Parameters
$field : string
$values : ArrayHash<string|int, mixed>
Return values
array{id: ?int, failed: bool, release?: ?int, created?: int}

saveOperatorAsset()

Saves the uploaded file as an Asset and returns its id (null when the save failed).

private saveOperatorAsset(int|null $currentId, FileUpload $upload) : int|null

Fail-soft: when the image is not saved, the form does not fail; the previous value stays and the user gets the error message from the settings save above.

Parameters
$currentId : int|null
$upload : FileUpload
Return values
int|null

saveOperatorForm()

private saveOperatorForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool
On this page

Search results