ArticleFormTrait
Edit/add form of an article.
The skeleton (check, domain translator, save/update/cancel buttons, return to the previous page) comes from BasePresenter::createForm().
The main image is uploaded via the reusable component
ImageUpload (field
Form::addImageUpload()). The bytes go to the Api in the $meta of the save payload;
variants and the Asset entity are saved by ArticleManager.
Categories, tags and galleries are many-to-many associations (id references); on save they are resolved to managed entities through the respective managers.
Table of Contents
Constants
- ART_DT_FORMAT : mixed = 'Y-m-d\TH:i'
- Value format of `<input type=datetime-local>`.
Methods
- createComponentEditForm() : Form
- addAdvertMultiplier() : void
- Advert multiplier (via `ArticleAdvertRel`; row = hidden `advertId` + label, order = row sequence).
- addCategoryMultiplier() : void
- Category multiplier (many-to-many via picker; row = hidden `categoryId` + label).
- addGalleryMultiplier() : void
- Gallery multiplier (many-to-many via picker; row = hidden `galleryId` + label).
- addMainFields() : void
- Untranslated fields: author, link, publish date, activation, main image.
- addPollMultiplier() : void
- Poll multiplier (via `ArticlePollRel`; row = hidden `pollId` + label, order = row sequence).
- addRelationFields() : void
- Tags as a multiselect (few items); categories and galleries use the picker multiplier.
- addTranslationFields() : void
- Multilingual fields: one set per language (`<field>_<langId>`), active according to the checkbox.
- applyRelations() : void
- Rewrites the many-to-many associations from the selection: categories/galleries from the picker rows (multiplier), tags from the multiselect. Entities are resolved through the managers (managed references; Doctrine synchronizes the join tables).
- buildArticleAdvertRels() : ArrayCollection<int, ArticleAdvertRel>
- Builds the join entities for the advert association. `order` is the row position in the multiplier (continuous 0..n by sequence). The hydrator fills `article` (owner) from the cascade.
- buildArticleEntity() : Article
- buildArticlePollRels() : ArrayCollection<int, ArticlePollRel>
- Builds the join entities for the poll association (analogous to adverts).
- collectImageMeta() : array<string, mixed>
- Builds `$meta` for save: a new image (base64) and/or the delete flag.
- currentLangId() : int|null
- Id of the current language (for labels); null when unknown.
- fetchByIds() : array<int, object>
- Resolves entities by id (managed references for the many-to-many write).
- getFormLanguages() : array<int, Language>
- Languages for the multilingual form fields (admin `LanguageManager`).
- intIds() : array<int, int>
- Converts a mixed id array from the form to `list<int>` (without empty/zero values).
- pollLabel() : string
- Poll question in the current language (first non-empty as fallback), used as the picker label.
- prepareTagOptions() : array<int, string>
- Tag options as `id => name` (current language, first non-empty as fallback).
- rowIds() : array<int, int>
- Collects unique positive ids from the multiplier rows (each row has a hidden `<field>`).
- saveArticleForm() : bool
- Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
- setArticleFormDefaults() : void
- str() : string
- Safely converts a mixed form value to string.
- translatedName() : string
- Entity name (with `translations`) in the current language, first non-empty as fallback.
Constants
ART_DT_FORMAT
Value format of `<input type=datetime-local>`.
private
mixed
ART_DT_FORMAT
= 'Y-m-d\TH:i'
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormaddAdvertMultiplier()
Advert multiplier (via `ArticleAdvertRel`; row = hidden `advertId` + label, order = row sequence).
private
addAdvertMultiplier(Form $form) : void
Parameters
- $form : Form
addCategoryMultiplier()
Category multiplier (many-to-many via picker; row = hidden `categoryId` + label).
private
addCategoryMultiplier(Form $form) : void
Parameters
- $form : Form
addGalleryMultiplier()
Gallery multiplier (many-to-many via picker; row = hidden `galleryId` + label).
private
addGalleryMultiplier(Form $form) : void
Parameters
- $form : Form
addMainFields()
Untranslated fields: author, link, publish date, activation, main image.
private
addMainFields(Form $form) : void
Parameters
- $form : Form
addPollMultiplier()
Poll multiplier (via `ArticlePollRel`; row = hidden `pollId` + label, order = row sequence).
private
addPollMultiplier(Form $form) : void
Parameters
- $form : Form
addRelationFields()
Tags as a multiselect (few items); categories and galleries use the picker multiplier.
private
addRelationFields(Form $form) : void
Parameters
- $form : Form
addTranslationFields()
Multilingual fields: one set per language (`<field>_<langId>`), active according to the checkbox.
private
addTranslationFields(Form $form) : void
Parameters
- $form : Form
applyRelations()
Rewrites the many-to-many associations from the selection: categories/galleries from the picker rows (multiplier), tags from the multiselect. Entities are resolved through the managers (managed references; Doctrine synchronizes the join tables).
private
applyRelations(Article $article, ArrayHash<string|int, mixed> $values) : void
Parameters
- $article : Article
- $values : ArrayHash<string|int, mixed>
buildArticleAdvertRels()
Builds the join entities for the advert association. `order` is the row position in the multiplier (continuous 0..n by sequence). The hydrator fills `article` (owner) from the cascade.
private
buildArticleAdvertRels(ArrayHash<string|int, mixed> $values) : ArrayCollection<int, ArticleAdvertRel>
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
ArrayCollection<int, ArticleAdvertRel>buildArticleEntity()
private
buildArticleEntity(ArrayHash<string|int, mixed> $values) : Article
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
ArticlebuildArticlePollRels()
Builds the join entities for the poll association (analogous to adverts).
private
buildArticlePollRels(ArrayHash<string|int, mixed> $values) : ArrayCollection<int, ArticlePollRel>
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
ArrayCollection<int, ArticlePollRel>collectImageMeta()
Builds `$meta` for save: a new image (base64) and/or the delete flag.
private
collectImageMeta(ArrayHash<string|int, mixed> $values) : array<string, mixed>
The Api turns it into an Asset (variants) and sets the FK to the main image.
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
array<string, mixed>currentLangId()
Id of the current language (for labels); null when unknown.
private
currentLangId() : int|null
Return values
int|nullfetchByIds()
Resolves entities by id (managed references for the many-to-many write).
private
fetchByIds(Manager<BaseEntity, ServiceInterface<string|int, BaseEntity>> $manager, array<int, int> $ids) : array<int, object>
Parameters
- $manager : Manager<BaseEntity, ServiceInterface<string|int, BaseEntity>>
- $ids : array<int, int>
Return values
array<int, object>getFormLanguages()
Languages for the multilingual form fields (admin `LanguageManager`).
private
getFormLanguages() : array<int, Language>
Return values
array<int, Language>intIds()
Converts a mixed id array from the form to `list<int>` (without empty/zero values).
private
intIds(mixed $values) : array<int, int>
Parameters
- $values : mixed
Return values
array<int, int>pollLabel()
Poll question in the current language (first non-empty as fallback), used as the picker label.
private
pollLabel(Poll $poll) : string
Parameters
- $poll : Poll
Return values
stringprepareTagOptions()
Tag options as `id => name` (current language, first non-empty as fallback).
private
prepareTagOptions() : array<int, string>
Return values
array<int, string>rowIds()
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>saveArticleForm()
Saves the form data. The redirect is handled by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
private
saveArticleForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsetArticleFormDefaults()
private
setArticleFormDefaults(Form $form) : void
Parameters
- $form : Form
str()
Safely converts a mixed form value to string.
private
str(mixed $value) : string
Parameters
- $value : mixed
Return values
stringtranslatedName()
Entity name (with `translations`) in the current language, first non-empty as fallback.
private
translatedName(object $entity) : string
Parameters
- $entity : object