CoolCMS API

FeedEdit extends BaseComponent
in package
uses AdminComponentFormTrait, FormHelpersTrait, FormTrait, ParameterTreeTrait, GenerateTrait

FinalYes

Renders the feed add/edit form as the page content (not in a modal).

The form has two sections: base data and the parameter tree. Per-product-set overrides (FeedParameterRel) live in the ProductSetEdit feeds tab and category mappings (FeedProductCategoryRel) in the category form.

Saving touches only the base fields and the parameter tree:

  • base fields use the generic object-graph save; categoryRels is in the Api FeedManager::$defaultSkipFields, otherwise the empty form collection would delete the mappings of all categories through orphan removal;
  • parameters go through a dedicated bridge action (FeedManager::saveParameterTree()) outside the generic save, in the same form submit (FormTrait::saveFeedForm()).

Table of Contents

Constants

EDIT_INCLUDES  : array<int, string> = ['language', 'currency']
Category mappings are not included: the form does not edit them and the Api `defaultSkipFields` excludes them from the save path.
GENERATE_LOCK_NAME  : string = 'cron.eshop.feed.generate'

Properties

$container  : Container
$routerDispatcher  : RouterDispatcher
$translator  : ITranslator
$appContext  : AppContext
$componentParameters  : array<string, mixed>
$currencyContext  : CurrencyContext|null
$deviceDetector  : DeviceDetector|null
$languageContext  : LanguageContext|null
$localizationContext  : LocalizationContext|null
$settingContext  : SettingContext
$themeContext  : ThemeContext|null
$translatorDomain  : string
$adminLanguageManager  : LanguageManager
$cronLockManager  : CronLockManager
$currencyManager  : CurrencyManager
$editedFeed  : Feed|null
Edited feed (null when adding), set by {@see resolveEditedFeed()}.
$feedCurrencies  : array<int, Currency>
$feedId  : int|null
Per-instance context from {@see FeedEditFactory::create()}; null when adding.
$feedLanguages  : array<int, Language>
$feedManager  : FeedManager
$feedParameterActionManager  : FeedParameterActionManager
$feedParameterActionOptions  : array<int, NotTranslate>
$feedParameterTreeCache  : array<int, array<string, mixed>>|null
$formActionsFactory  : FormActionsFactory

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
createComponent()  : IComponent|null
getAppContext()  : AppContext
getComponentParameter()  : mixed
Returns a component parameter, or null when it is not set.
getContainer()  : Container
getCurrencyContext()  : CurrencyContext|null
getLanguageContext()  : LanguageContext|null
getLocalizationContext()  : LocalizationContext|null
getRouterDispatcher()  : RouterDispatcher
getSettingContext()  : SettingContext
getSettings()  : array<int, array<string, mixed>>
getThemeContext()  : ThemeContext|null
handleGenerateNow()  : void
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
onCreate()  : void
render()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
createAdminComponentForm()  : Form
createComponentAdminFormActions()  : FormActions
createComponentEditForm()  : Form
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
intOrNull()  : int|null
setTemplateFile()  : void
setTranslator()  : self
str()  : string
strOrNull()  : string|null
addFeedBaseFields()  : void
addFeedParameterNodeControls()  : void
addFeedParameterTreeMultiplier()  : void
buildFeedEntity()  : Feed
buildParameterTreeDefaultRows()  : array<int, array<string, mixed>>
Converts the stored tree into nested default rows (two levels) for the multiplier, passed through `$form->setDefaults()` in {@see FormTrait::setFeedFormDefaults()}.
createMultiplierComponent()  : Multiplier<string|int, IComponent>
Creates a multiplier for the component.
createNewComponentInstance()  : IComponent|null
Creates a new component instance without adding it to the presenter; used by the multiplier.
createStandardComponent()  : IComponent|null
Creates a standard component (not a multiplier).
currentLangIdOrDefault()  : int
extractSubmittedTree()  : array<int, array<string, mixed>>
Converts the nested `$values->parameters` (multiplier) into the shape expected by {@see \App\UI\Admin\Eshop\Models\Managers\FeedManager::saveParameterTree()}.
httpRequest()  : IRequest
Returns the HTTP request through the presenter; a control has no `getHttpRequest()`.
isSignalRequest()  : bool
Tells whether a signal is being handled; a control has no `getSignal()`, only the presenter has.
loadFeedParameterTree()  : array<int, array<string, mixed>>
Returns the feed parameter tree, memoized per request because `render()` and `createComponentEditForm()` can both ask for the prefill.
loadFeedSelectData()  : void
Loads the select data (languages, currencies, actions) once per request.
resolveEditedFeed()  : Feed|null
saveFeedForm()  : bool
setFeedFormDefaults()  : void
Prefills the base fields and the parameter tree multiplier (including the nested level) in a single `setDefaults()`.

Constants

EDIT_INCLUDES

Category mappings are not included: the form does not edit them and the Api `defaultSkipFields` excludes them from the save path.

public array<int, string> EDIT_INCLUDES = ['language', 'currency']

GENERATE_LOCK_NAME

private string GENERATE_LOCK_NAME = 'cron.eshop.feed.generate'

Properties

$componentParameters

protected array<string, mixed> $componentParameters = []

component parameters set by setComponentParameter()

$translatorDomain

protected string $translatorDomain = 'admin.eshop.presenters.feed'

$editedFeed

Edited feed (null when adding), set by {@see resolveEditedFeed()}.

private Feed|null $editedFeed

$feedId read-only

Per-instance context from {@see FeedEditFactory::create()}; null when adding.

private int|null $feedId

$feedParameterActionOptions

private array<int, NotTranslate> $feedParameterActionOptions = []

id => translated action name (falls back to the raw action string).

$feedParameterTreeCache

private array<int, array<string, mixed>>|null $feedParameterTreeCache = null

tree memoized per request (see loadFeedParameterTree())

Methods

__call()

Dispatches `renderXyz()` to `render('Xyz', ...$args)`.

public __call(string $name, array<string|int, mixed> $args) : mixed

Called only when the component has no renderXyz() method of its own.

Parameters
$name : string
$args : array<string|int, mixed>

__construct()

public __construct(FeedManager $feedManager, FeedParameterActionManager $feedParameterActionManager, LanguageManager $adminLanguageManager, CurrencyManager $currencyManager, FormActionsFactory $formActionsFactory, CronLockManager $cronLockManager, int|null $feedId) : mixed
Parameters
$feedManager : FeedManager
$feedParameterActionManager : FeedParameterActionManager
$adminLanguageManager : LanguageManager
$currencyManager : CurrencyManager
$formActionsFactory : FormActionsFactory
$cronLockManager : CronLockManager
$feedId : int|null

createComponent()

public createComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

getComponentParameter()

Returns a component parameter, or null when it is not set.

public getComponentParameter(string $name) : mixed
Parameters
$name : string

getContainer()

public getContainer() : Container
Return values
Container

getSettings()

public getSettings() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

handleGenerateNow()

public handleGenerateNow() : void
Attributes
#[Requires]
$methods: 'POST'

hasServiceByType()

Returns whether the container has a service of the given type.

public hasServiceByType(string $className) : bool

The name is composed dynamically (module plus component), so class_exists() runs first, and a true result guarantees a valid type.

Parameters
$className : string
Tags
phpstan-assert-if-true

class-string $className

Return values
bool

setComponentParameter()

Sets a component parameter.

public setComponentParameter(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed

typedComponent()

Returns a subcomponent with a verified type.

public typedComponent(string $name, T> $type) : T

Use it instead of an inline @var above $this['x'] (which does not narrow the type) and instead of the generic IComponent that $this['x'] returns. See Form::typedComponent().

Parameters
$name : string
$type : T>
Tags
template
Return values
T

createAdminComponentForm()

protected createAdminComponentForm(callable(ArrayHash<string|int, mixed>, Form=): bool $processData[, callable(string): void|null $afterSave = null ]) : Form
Parameters
$processData : callable(ArrayHash<string|int, mixed>, Form=): bool

Saves the data; returns success (handles its own flash).

$afterSave : callable(string): void|null = null

When set, replaces the default backKey/redirect logic after a successful $processData; the parameter is the clicked submit name (update or save). The hidden backKey stays in the form but is unused. For a component hosted in a modal shell, where a page redirect makes no sense (the modal is an AJAX shell over the presenter page).

Return values
Form

createComponentEditForm()

protected createComponentEditForm() : Form
Return values
Form

frontPresenter()

Returns the front presenter the component is attached to (null outside the front end or when detached).

protected frontPresenter() : BasePresenter|null
Return values
BasePresenter|null

getTranslator()

protected getTranslator() : ITranslator
Return values
ITranslator

intOrNull()

protected intOrNull(mixed $value) : int|null
Parameters
$value : mixed
Return values
int|null

setTemplateFile()

protected setTemplateFile(string $dir, string $filename) : void
Parameters
$dir : string
$filename : string

setTranslator()

protected setTranslator(ITranslator $translator) : self
Parameters
$translator : ITranslator
Return values
self

str()

protected str(mixed $value) : string
Parameters
$value : mixed
Return values
string

strOrNull()

protected strOrNull(mixed $value) : string|null
Parameters
$value : mixed
Return values
string|null

addFeedBaseFields()

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

addFeedParameterNodeControls()

private addFeedParameterNodeControls(Container $node) : void
Parameters
$node : Container

buildFeedEntity()

private buildFeedEntity(ArrayHash<string|int, mixed> $values) : Feed
Parameters
$values : ArrayHash<string|int, mixed>
Return values
Feed

buildParameterTreeDefaultRows()

Converts the stored tree into nested default rows (two levels) for the multiplier, passed through `$form->setDefaults()` in {@see FormTrait::setFeedFormDefaults()}.

private buildParameterTreeDefaultRows() : array<int, array<string, mixed>>

IMPORTANT: never call Multiplier::addCopy() plus Container::setValues() on single copies. addCopy(?int $number) is typed ?int (a string index throws a TypeError), and the multiplier controls the number of copies itself in createCopies() from the values set. The nested level (children) is passed as a plain nested array.

Return values
array<int, array<string, mixed>>

createMultiplierComponent()

Creates a multiplier for the component.

private createMultiplierComponent(string $name) : Multiplier<string|int, IComponent>
Parameters
$name : string
Return values
Multiplier<string|int, IComponent>

createNewComponentInstance()

Creates a new component instance without adding it to the presenter; used by the multiplier.

private createNewComponentInstance(string $baseName[, int|string|null $uniqueKey = null ]) : IComponent|null
Parameters
$baseName : string
$uniqueKey : int|string|null = null
Return values
IComponent|null

createStandardComponent()

Creates a standard component (not a multiplier).

private createStandardComponent(string $name) : IComponent|null
Parameters
$name : string
Return values
IComponent|null

currentLangIdOrDefault()

private currentLangIdOrDefault() : int
Return values
int

extractSubmittedTree()

Converts the nested `$values->parameters` (multiplier) into the shape expected by {@see \App\UI\Admin\Eshop\Models\Managers\FeedManager::saveParameterTree()}.

private extractSubmittedTree(mixed $rows) : array<int, array<string, mixed>>
Parameters
$rows : mixed
Return values
array<int, array<string, mixed>>

httpRequest()

Returns the HTTP request through the presenter; a control has no `getHttpRequest()`.

private httpRequest() : IRequest
Return values
IRequest

isSignalRequest()

Tells whether a signal is being handled; a control has no `getSignal()`, only the presenter has.

private isSignalRequest() : bool
Return values
bool

loadFeedParameterTree()

Returns the feed parameter tree, memoized per request because `render()` and `createComponentEditForm()` can both ask for the prefill.

private loadFeedParameterTree() : array<int, array<string, mixed>>
Return values
array<int, array<string, mixed>>

loadFeedSelectData()

Loads the select data (languages, currencies, actions) once per request.

private loadFeedSelectData() : void

resolveEditedFeed()

private resolveEditedFeed() : Feed|null
Return values
Feed|null

saveFeedForm()

private saveFeedForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
$values : ArrayHash<string|int, mixed>
Return values
bool

setFeedFormDefaults()

Prefills the base fields and the parameter tree multiplier (including the nested level) in a single `setDefaults()`.

private setFeedFormDefaults(Form $form) : void

IMPORTANT: the multiplier is filled only through nested arrays in the defaults, never by addCopy()/setValues() on single copies; see ParameterTreeTrait::buildParameterTreeDefaultRows().

Parameters
$form : Form
On this page

Search results