ReferenceFormTrait
Reference (portfolio) add/edit form: company (select), client, realization date, link, logo, gallery, categories and per-language tabs (title, description, quote).
The skeleton (translator, back key, save/apply/cancel buttons) is
BasePresenter::createForm(); multilingual fields and safe
conversions come from AdminFormHelpersTrait.
A reference has no activated, only public, so there is no header toggle and public
is a plain checkbox. Under it sit three presentation subsets: inLogos (supplier logo
strip), inList (reference list) and featured (picked work on the home page).
Image channels:
- logo via Form::addImageUpload(): the bytes go to
$meta['logo']and ReferenceManager creates theAssetvariants, - gallery (photos and videos) via the
uploaderDropzone component: the ordered list (existing + new) goes to the Api in$meta['orderedAssets']; the first item is the main photo (imageId). The form carries only the hiddendropzoneToken.
Categories (M2M) are edited by a Picker in a Multiplier; row ids go to the Api in
$meta['categoryIds'] (the join table has no entity; the Api afterSave syncs it).
Table of Contents
Methods
- createComponentEditForm() : Form
- addBasicFields() : void
- Company, client, realization date, link, order, visibility and logo.
- addCategoryMultiplier() : void
- Category multiplier (M2M via Picker; a row is hidden `categoryId` + label).
- addGalleryFields() : void
- The gallery is a Dropzone uploader (`uploader` component). The form carries only the hidden `dropzoneToken` (identifies the temp folder); the component holds the selected files (AJAX upload to temp) and the ordered list (existing + new) arrives in the POST as `uploaderItems[]`. On re-render (validation error) the token is read from the POST.
- addTranslationFields() : void
- Multilingual fields (title, description, quote) per language, active per checkbox.
- applyCategories() : void
- Overwrites the M:N relation to categories from the picker rows. The object graph keeps the state for editing; the authoritative join-table write is done by the Api `afterSave` from `meta['categoryIds']`.
- buildCategoryRowDefaults() : array<int, array{categoryId: int, category: string}>
- Maps categories to picker rows (hidden id + label = name in the current language).
- buildReferenceEntity() : Reference
- collectLogoMeta() : array<string, mixed>
- Builds `$meta` for the logo: a new image (base64) and/or the delete flag.
- 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): `existing` = id of an existing item, `dropzone` = a newly uploaded file in the temp folder (its `path` is looked up by name). The order is the sequence; the first item is the main photo.
- fetchCategories() : array<int, Category>
- Loads categories by id (managed references for the M:N write).
- parseDate() : DateTime|null
- Converts an `<input type=date>` value to `DateTime`, or null when empty/invalid.
- rowIds() : array<int, int>
- Collects unique positive ids from the multiplier rows (each row has a hidden `<field>`).
- saveReferenceForm() : bool
- Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
- setReferenceFormDefaults() : void
- tr() : NotTranslate
- Translates a key in the form domain into a ready string (for fields with `setTranslator(null)`).
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormaddBasicFields()
Company, client, realization date, link, order, visibility and logo.
private
addBasicFields(Form $form) : void
Parameters
- $form : Form
addCategoryMultiplier()
Category multiplier (M2M via Picker; a row is hidden `categoryId` + label).
private
addCategoryMultiplier(Form $form) : void
Parameters
- $form : Form
addGalleryFields()
The gallery is a Dropzone uploader (`uploader` component). The form carries only the hidden `dropzoneToken` (identifies the temp folder); the component holds the selected files (AJAX upload to temp) and the ordered list (existing + new) arrives in the POST as `uploaderItems[]`. On re-render (validation error) the token is read from the POST.
private
addGalleryFields(Form $form) : void
Parameters
- $form : Form
addTranslationFields()
Multilingual fields (title, description, quote) per language, active per checkbox.
private
addTranslationFields(Form $form) : void
Parameters
- $form : Form
applyCategories()
Overwrites the M:N relation to categories from the picker rows. The object graph keeps the state for editing; the authoritative join-table write is done by the Api `afterSave` from `meta['categoryIds']`.
private
applyCategories(Reference $reference, ArrayHash<string|int, mixed> $values) : void
Parameters
- $reference : Reference
- $values : ArrayHash<string|int, mixed>
buildCategoryRowDefaults()
Maps categories to picker rows (hidden id + label = name in the current language).
private
buildCategoryRowDefaults(Reference $reference) : array<int, array{categoryId: int, category: string}>
Parameters
- $reference : Reference
Return values
array<int, array{categoryId: int, category: string}>buildReferenceEntity()
private
buildReferenceEntity(ArrayHash<string|int, mixed> $values) : Reference
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
ReferencecollectLogoMeta()
Builds `$meta` for the logo: a new image (base64) and/or the delete flag.
private
collectLogoMeta(ArrayHash<string|int, mixed> $values) : array<string, mixed>
The Api creates the Asset (variants) and sets the FK logoId.
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
array<string, mixed>collectOrderedAssets()
Builds `meta['orderedAssets']` for the Api `afterSave` from the ordered dropzone list (`uploaderItems[]` from the POST): `existing` = id of an existing item, `dropzone` = a newly uploaded file in the temp folder (its `path` is looked up by name). The order is the sequence; the first item is the main photo.
private
collectOrderedAssets(ArrayHash<string|int, mixed> $values) : array<int, array{type: string, imageId?: int, name?: string, path?: string, order: int}>
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 M:N write).
private
fetchCategories(array<int, int> $ids) : array<int, Category>
Parameters
- $ids : array<int, int>
Return values
array<int, Category>parseDate()
Converts an `<input type=date>` value to `DateTime`, or null when empty/invalid.
private
parseDate(mixed $value) : DateTime|null
Parameters
- $value : mixed
Return values
DateTime|nullrowIds()
Collects unique positive ids from the multiplier rows (each row has a hidden `<field>`).
private
rowIds(mixed $rows, string $field) : array<int, int>
Parameters
- $rows : mixed
- $field : string
Return values
array<int, int>saveReferenceForm()
Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
private
saveReferenceForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsetReferenceFormDefaults()
private
setReferenceFormDefaults(Form $form) : void
Parameters
- $form : Form
tr()
Translates a key in the form domain into a ready string (for fields with `setTranslator(null)`).
private
tr(string $key) : NotTranslate
IMPORTANT: the result goes to setPrompt()/setRequired() on a field with
setTranslator(null). Prompt and items respect the control override, but Nette
getLabel() and Validator::formatMessage() always take the translator from the form;
without NotTranslate the finished text would be translated again as a key and Tracy
would report a missing translation.
Parameters
- $key : string