CoolCMS API

AssetUsageSettings extends BaseComponent
in package
uses PrivilegeGuardTrait

Assigns image variants to the image usages of one module (blog, e-shop, bazaar, comcat and discussion settings) or of all modules (the "Usage" tab of the variants screen).

Has its own form and button (it sits below the module settings form; a nested <form> is impossible) and saves the whole set of usages in one transaction through the single Api call api/system/asset-usage/save-assignments: everything passes or nothing.

Per usage: "store original" and a table of variants (checkbox, alias = folder on disk, position). All active variants are shown plus inactive ones that are already assigned (otherwise saving would silently drop them).

Validation runs twice: here up front over the same rules (AssetVariantPlan::validateAssignments()) so the error lands on the row field, and on the Api, which is the authority. Row errors render at the row alias; errors of a whole usage (missing thumb/big) render above the table, because the admin layout shows form-level errors nowhere else.

IMPORTANT: the privilege gate is the first statement of onSettingsFormSuccess(); the submit is a separate POST that bypasses any action of the host. The host supplies the key via setPrivilege(); without it the gate falls back to the variants screen key :Admin:System:AssetVariant:edit.

Table of Contents

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|null
$assetUsageManager  : AssetUsageManager
$data  : array{usages: list>, variants: list>}|null|false
$moduleId  : int|null
Module whose usages are edited; null means all modules (the "Usage" tab).
$privilege  : string
Admin key allowed to save the assignments (supplied by the host). Empty means `:Admin:System:AssetVariant:edit`.
$showModuleHeading  : bool|null
Module heading above the usages; null derives it from whether the component shows all modules.
$showTitle  : bool
Title and intro above the form (on the "Usage" tab only the first module form has them).
$usageErrors  : array<int, array<int, string>>

Methods

__call()  : mixed
Dispatches `renderXyz()` to `render('Xyz', ...$args)`.
__construct()  : mixed
createComponent()  : IComponent|null
createComponentSettingsForm()  : Form
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
hasServiceByType()  : bool
Returns whether the container has a service of the given type.
initializeAllContexts()  : void
injectDeviceDetector()  : void
onCreate()  : void
onSettingsFormSuccess()  : void
Values are read per usage container (`usage_<id>`), not from the flat `$values`.
render()  : void
setAppContext()  : $this
setComponentParameter()  : void
Sets a component parameter.
setCurrencyContext()  : $this
setLanguageContext()  : $this
setLocalizationContext()  : $this
setModule()  : static
setPrivilege()  : static
setSection()  : static
Header look: title plus intro and module heading (the "Usage" tab renders one form per module).
setSettingContext()  : $this
setThemeContext()  : $this
setup()  : void
setupAppContext()  : void
typedComponent()  : T
Returns a subcomponent with a verified type.
frontPresenter()  : BasePresenter|null
Returns the front presenter the component is attached to (null outside the front end or when detached).
getTranslator()  : ITranslator
isTargetAllowed()  : bool
Returns whether the logged-in user may open the given admin target. For visibility (tiles, autocomplete, buttons); it does not throw.
requirePrivilege()  : void
Throws 403 when the logged-in user lacks the given admin privilege.
resolvePageTarget()  : string|null
Returns the RBAC key of the target page: `<presenter>:<action>`, e.g. `:Admin:System:User:show`.
setTemplateFile()  : void
setTranslator()  : self
applyErrors()  : void
buildDefaults()  : array<string, mixed>
buildRows()  : array<int, array<int, array{variantId: int, name: string, maxWidth: int, maxHeight: int, resizeMode: string, watermark: bool, activated: bool, assigned: bool, alias: string|null, position: int}>>
Builds the table rows of each usage: active variants plus inactive assigned ones, assigned first by position, then the rest by variant order.
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).
int()  : int
loadData()  : array{usages: list>, variants: list>}|null
str()  : string

Properties

$componentParameters

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

component parameters set by setComponentParameter()

$translatorDomain

protected string|null $translatorDomain = 'admin.system.components.assetUsageSettings'

$data

private array{usages: list>, variants: list>}|null|false $data = false

false = not loaded yet

$moduleId

Module whose usages are edited; null means all modules (the "Usage" tab).

private int|null $moduleId = null

$privilege

Admin key allowed to save the assignments (supplied by the host). Empty means `:Admin:System:AssetVariant:edit`.

private string $privilege = ''

$showModuleHeading

Module heading above the usages; null derives it from whether the component shows all modules.

private bool|null $showModuleHeading = null

$showTitle

Title and intro above the form (on the "Usage" tab only the first module form has them).

private bool $showTitle = true

$usageErrors

private array<int, array<int, string>> $usageErrors = []

translated errors of a whole usage, keyed by usageId

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>

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>>

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

onSettingsFormSuccess()

Values are read per usage container (`usage_<id>`), not from the flat `$values`.

public onSettingsFormSuccess(Form $form) : void
Parameters
$form : Form

setComponentParameter()

Sets a component parameter.

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

setModule()

public setModule(int|null $moduleId) : static
Parameters
$moduleId : int|null
Return values
static

setPrivilege()

public setPrivilege(string $privilege) : static
Parameters
$privilege : string
Return values
static

setSection()

Header look: title plus intro and module heading (the "Usage" tab renders one form per module).

public setSection(bool $showTitle, bool $showModuleHeading) : static
Parameters
$showTitle : bool
$showModuleHeading : bool
Return values
static

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

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

isTargetAllowed()

Returns whether the logged-in user may open the given admin target. For visibility (tiles, autocomplete, buttons); it does not throw.

protected isTargetAllowed(string|null $key) : bool

IMPORTANT: fail-closed like requirePrivilege(): an empty key and a presenter without isAllowed() both mean no. A component that skips this question lists the target to everyone.

Parameters
$key : string|null
Return values
bool

requirePrivilege()

Throws 403 when the logged-in user lacks the given admin privilege.

protected requirePrivilege(string $key) : void

Call it as the first statement of a mutating signal, before loading data, so the check cannot be bypassed by something being written first.

Parameters
$key : string

resolvePageTarget()

Returns the RBAC key of the target page: `<presenter>:<action>`, e.g. `:Admin:System:User:show`.

protected static resolvePageTarget(object|null $page) : string|null

Same interpretation as Menu::filterByPrivileges(), BasePresenter::authorizeListing() and PrivilegeCheckTrait::checkCurrentPrivilege(). The key is derived from the page target only, never from a file or class name.

Returns null when the page is missing or has no presenter, so there is nothing to allow.

Parameters
$page : object|null

AdminPage entity (hydrated, hence just object)

Return values
string|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

applyErrors()

private applyErrors(Container $container, int $usageId, array<int, array<string|int, mixed>> $errors) : void
Parameters
$container : Container
$usageId : int
$errors : array<int, array<string|int, mixed>>

{code, variantId, alias}

buildDefaults()

private buildDefaults(array{usages: list>, variants: list>} $data) : array<string, mixed>
Parameters
$data : array{usages: list>, variants: list>}
Return values
array<string, mixed>

buildRows()

Builds the table rows of each usage: active variants plus inactive assigned ones, assigned first by position, then the rest by variant order.

private buildRows(array{usages: list>, variants: list>} $data) : array<int, array<int, array{variantId: int, name: string, maxWidth: int, maxHeight: int, resizeMode: string, watermark: bool, activated: bool, assigned: bool, alias: string|null, position: int}>>
Parameters
$data : array{usages: list>, variants: list>}
Return values
array<int, array<int, array{variantId: int, name: string, maxWidth: int, maxHeight: int, resizeMode: string, watermark: bool, activated: bool, assigned: bool, alias: string|null, position: int}>>

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

int()

private static int(mixed $value) : int
Parameters
$value : mixed
Return values
int

loadData()

private loadData() : array{usages: list>, variants: list>}|null
Return values
array{usages: list>, variants: list>}|null

str()

private static str(mixed $value) : string
Parameters
$value : mixed
Return values
string
On this page

Search results