FormTrait
Requires in the host class: - $this->translator - $this->translatorDomain - $this->watchdogId (int) - $this->watchdogManager (WatchdogManager) - $this->categoryManager (CategoryManager) - $this->categorySuggestFactory (CategorySuggestFactory) - $this->regionManager (RegionManager) - $this->regionSuggestFactory (RegionSuggestFactory) - $this->languageManager (LanguageManager) - $this->parameterManager (ParameterManager) - $this->languageContext - updateModalContent(): void (from `ModalTrait`) - createSuccessContent(): string (from `ModalTrait`) - createFormContent(): string (from `ModalTrait`) - getPresenter() - getPresenterIfExists()
Table of Contents
Constants
- STATE_PARAMETER_KEY : string = 'state'
- Key of the parent parameter "state".
- TYPE_PARAMETER_KEY : string = 'type'
- Key of the parent parameter "type" (options are its children, an advert stores the option id in `value`).
Methods
- onError() : void
- Handles an invalid form: the modal must be redrawn, otherwise the user does not see the field errors (region, e-mail). Errors without a field (CSRF) have no place in the template, so they go to a generic flash.
- onSuccess() : void
- onValidate() : void
- Validates the form: the category is required and text typed without a suggestion selected is an error. Without a region the localization country is watched; when the localization has none, the region is required. Typed region text without a selection is an error (otherwise a typo would save the whole country).
- createComponentCategorySuggest() : CategorySuggest
- Creates the category suggest (shared component, source = the module's Front `CategoryManager`).
- createComponentForm() : Form
- createComponentRegionSuggest() : RegionSuggest
- Creates the region suggest. A watchdog can watch a country, county, district or municipality; matching goes through the ancestors of the advert region.
- prepareFormTemplate() : void
- getCategoryLabel() : string
- getParameterLabel() : string
- isSelectableCategory() : bool
- Checks that the selected category exists, is active and is not admin-only (any tree level).
- isSelectableRegion() : bool
- Checks that the selected region exists and is active (any tree level).
- isTyped() : bool
- Checks that the user typed something into the suggest field (regardless of a selection).
- prepareLanguageList() : array<int, string>
- prepareStateList() : array<int, string>
- prepareTypeList() : array<int, string>
- resolveCategoryLabel() : string
- Returns the saved category label for editing (suggest text); empty text when it does not exist.
- resolveDefaultRegionId() : int|null
- Returns the website localization country (`cms_system_localizations.cms_system_regions_region_id`).
- resolveLanguageId() : int
- resolveRegionId() : int
Constants
STATE_PARAMETER_KEY
Key of the parent parameter "state".
private
string
STATE_PARAMETER_KEY
= 'state'
TYPE_PARAMETER_KEY
Key of the parent parameter "type" (options are its children, an advert stores the option id in `value`).
private
string
TYPE_PARAMETER_KEY
= 'type'
Methods
onError()
Handles an invalid form: the modal must be redrawn, otherwise the user does not see the field errors (region, e-mail). Errors without a field (CSRF) have no place in the template, so they go to a generic flash.
public
onError(Form $form) : void
Parameters
- $form : Form
onSuccess()
public
onSuccess(Form $form, ArrayHash $values) : void
Parameters
- $form : Form
- $values : ArrayHash
onValidate()
Validates the form: the category is required and text typed without a suggestion selected is an error. Without a region the localization country is watched; when the localization has none, the region is required. Typed region text without a selection is an error (otherwise a typo would save the whole country).
public
onValidate(Container $form) : void
Parameters
- $form : Container
createComponentCategorySuggest()
Creates the category suggest (shared component, source = the module's Front `CategoryManager`).
protected
createComponentCategorySuggest() : CategorySuggest
A category of any level can be watched; matching with an advert goes through the watchdog category subtree.
Return values
CategorySuggestcreateComponentForm()
protected
createComponentForm() : Form
Return values
FormcreateComponentRegionSuggest()
Creates the region suggest. A watchdog can watch a country, county, district or municipality; matching goes through the ancestors of the advert region.
protected
createComponentRegionSuggest() : RegionSuggest
Return values
RegionSuggestprepareFormTemplate()
protected
prepareFormTemplate() : void
getCategoryLabel()
private
getCategoryLabel(Category $category, int|null $langId) : string
Parameters
- $category : Category
- $langId : int|null
Return values
stringgetParameterLabel()
private
getParameterLabel(Parameter $parameter, int|null $langId) : string
Parameters
- $parameter : Parameter
- $langId : int|null
Return values
stringisSelectableCategory()
Checks that the selected category exists, is active and is not admin-only (any tree level).
private
isSelectableCategory(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolisSelectableRegion()
Checks that the selected region exists and is active (any tree level).
private
isSelectableRegion(mixed $value) : bool
Parameters
- $value : mixed
Return values
boolisTyped()
Checks that the user typed something into the suggest field (regardless of a selection).
private
isTyped(TextInput $display) : bool
Parameters
- $display : TextInput
Return values
boolprepareLanguageList()
private
prepareLanguageList() : array<int, string>
Return values
array<int, string>prepareStateList()
private
prepareStateList() : array<int, string>
Return values
array<int, string>prepareTypeList()
private
prepareTypeList() : array<int, string>
Return values
array<int, string>resolveCategoryLabel()
Returns the saved category label for editing (suggest text); empty text when it does not exist.
private
resolveCategoryLabel(int $categoryId) : string
Parameters
- $categoryId : int
Return values
stringresolveDefaultRegionId()
Returns the website localization country (`cms_system_localizations.cms_system_regions_region_id`).
private
resolveDefaultRegionId() : int|null
Return values
int|nullresolveLanguageId()
private
resolveLanguageId() : int
Return values
intresolveRegionId()
private
resolveRegionId(mixed $value) : int
Parameters
- $value : mixed