CoolCMS API

CustomAsset extends CustomAsset
in package

Admin variant of a custom code asset, hydrated from `api/system/custom-asset` via `ApiBridge`.

Edited in the custom code library (Admin:System:CustomAsset) and assigned to pages in the custom code tab of the page form.

Attributes
#[Entity]
#[Table]
$name: 'cms_system_custom_assets'
#[TableAlias]
'customAsset'

Table of Contents

Properties

$active  : bool
$addToNewPages  : bool
A newly created page gets this snippet assigned automatically.
$code  : string
$cookieCategory  : string
$id  : int|null
$insertTime  : DateTime
$name  : string
$pages  : Collection
Pages the code runs on; this association alone decides it.
$placement  : string
$sort  : int
$type  : string
$updateDatetime  : DateTime|null

Methods

__construct()  : mixed
addPage()  : $this
callInitMethods()  : void
Calls `init{TraitName}()` for every used trait that defines such a method.
getActive()  : bool
getAddToNewPages()  : bool
getAllTraits()  : array<string, string>
Returns all traits the class uses, including those used by parent classes and nested traits.
getCode()  : string
getCookieCategory()  : string
getId()  : int|null
getInsertTime()  : DateTime
getName()  : string
getPage()  : TPage|null
getPages()  : Collection<int, TPage>
getPlacement()  : string
getPlacementEnum()  : CustomAssetPlacement|null
getSort()  : int
getType()  : string
getTypeEnum()  : CustomAssetType|null
getUpdateDatetime()  : DateTime|null
isActive()  : bool
isAddToNewPages()  : bool
isPersisted()  : bool
needsCookieConsent()  : bool
An empty category means the code runs without waiting for cookie consent.
pageCollectionInit()  : void
removePage()  : $this
setActive()  : $this
setAddToNewPages()  : $this
setCode()  : $this
setCookieCategory()  : $this
setId()  : $this
setInsertTime()  : $this
setName()  : $this
setPages()  : $this
setPlacement()  : $this
setSort()  : $this
setType()  : $this
setUpdateDatetime()  : $this
getTraitsRecursive()  : array<string, string>
Walks the trait list recursively and collects nested traits too.

Properties

$active

protected bool $active = true
Attributes
#[Column]
$name: 'active'
$type: 'boolean'

$addToNewPages

A newly created page gets this snippet assigned automatically.

protected bool $addToNewPages = false
Attributes
#[Column]
$name: 'add_to_new_pages'
$type: 'boolean'

$code

protected string $code = ''
Attributes
#[Column]
$name: 'code'
$type: 'text'

$cookieCategory

protected string $cookieCategory = ''
Attributes
#[Column]
$name: 'cookie_category'
$type: 'string'
$length: 20

$id

protected int|null $id = null
Attributes
#[Column]
$name: 'custom_asset_id'
$type: 'integer'
$options: ['unsigned' => true]
#[GeneratedValue]
#[Id]

$insertTime

protected DateTime $insertTime = new DateTime()
Attributes
#[Column]
$name: 'insert_time'
$type: 'datetime'
#[ExternalReadonly]

$name

protected string $name = ''
Attributes
#[Column]
$name: 'name'
$type: 'string'
$length: 255

$pages

Pages the code runs on; this association alone decides it.

protected Collection $pages

IMPORTANT: the asset owns the association, Page does not know about assets. Never save it through this collection (a generic save would wipe it on extract); use the Api operations sync-page, attach-all-pages and detach-all-pages.

No @var Collection<int, Page>: narrowing against the shared entity is not covariant for PHPStan. The element class is set by #[CollectionOf] (hydrator) and targetEntity (Doctrine).

Attributes
#[CollectionOf]
\App\UI\Admin\System\Models\Entities\Page::class
#[JoinTable]
$name: 'cms_system_custom_asset_page_relations'
$joinColumns: [new \Doctrine\ORM\Mapping\JoinColumn(name: 'cms_system_custom_assets_custom_asset_id', referencedColumnName: 'custom_asset_id')]
$inverseJoinColumns: [new \Doctrine\ORM\Mapping\JoinColumn(name: 'cms_system_pages_page_id', referencedColumnName: 'page_id')]
#[ManyToMany]
$targetEntity: \App\UI\Admin\System\Models\Entities\Page::class
$fetch: 'LAZY'

$placement

protected string $placement = CustomAssetPlacement::BodyEnd->value
Attributes
#[Column]
$name: 'placement'
$type: 'string'
$length: 15

$sort

protected int $sort = 0
Attributes
#[Column]
$name: 'sort'
$type: 'integer'
$options: ['unsigned' => true]

$type

protected string $type = CustomAssetType::Js->value
Attributes
#[Column]
$name: 'type'
$type: 'string'
$length: 10

$updateDatetime

protected DateTime|null $updateDatetime = null
Attributes
#[Column]
$name: 'update_datetime'
$type: 'datetime'
$nullable: true
#[ExternalReadonly]

Methods

__construct()

public __construct([int|null $id = null ][, string $name = '' ][, string $type = CustomAssetType::Js->value ][, string $placement = CustomAssetPlacement::BodyEnd->value ][, string $cookieCategory = '' ][, string $code = '' ][, bool $active = true ][, int $sort = 0 ][, bool $addToNewPages = false ][, DateTime $insertTime = new DateTime() ][, DateTime|null $updateDatetime = null ][, Collection $pages = new ArrayCollection() ]) : mixed
Parameters
$id : int|null = null
$name : string = ''
$type : string = CustomAssetType::Js->value
$placement : string = CustomAssetPlacement::BodyEnd->value
$cookieCategory : string = ''
$code : string = ''
$active : bool = true
$sort : int = 0
$addToNewPages : bool = false
$insertTime : DateTime = new DateTime()
$updateDatetime : DateTime|null = null
$pages : Collection = new ArrayCollection()

addPage()

public addPage(TPage $page) : $this
Parameters
$page : TPage
Return values
$this

callInitMethods()

Calls `init{TraitName}()` for every used trait that defines such a method.

public callInitMethods() : void

getActive()

public getActive() : bool
Return values
bool

getAddToNewPages()

public getAddToNewPages() : bool
Return values
bool

getAllTraits()

Returns all traits the class uses, including those used by parent classes and nested traits.

public getAllTraits() : array<string, string>
Return values
array<string, string>

getCode()

public getCode() : string
Return values
string

getCookieCategory()

public getCookieCategory() : string
Return values
string

getInsertTime()

public getInsertTime() : DateTime
Return values
DateTime

getName()

public getName() : string
Return values
string

getPage()

public getPage(int $pageId) : TPage|null
Parameters
$pageId : int
Return values
TPage|null

getPages()

public getPages() : Collection<int, TPage>
Return values
Collection<int, TPage>

getPlacement()

public getPlacement() : string
Return values
string

getType()

public getType() : string
Return values
string

getUpdateDatetime()

public getUpdateDatetime() : DateTime|null
Return values
DateTime|null

isActive()

public isActive() : bool
Return values
bool

isAddToNewPages()

public isAddToNewPages() : bool
Return values
bool

needsCookieConsent()

An empty category means the code runs without waiting for cookie consent.

public needsCookieConsent() : bool

NOTE: only "something is filled in" is checked, not whether the category exists in the cookie bar; the entity does not know the configuration. Validity is guarded by the form select, which offers exactly the bar categories (CookieConsentConfig::selectableKeys()).

Return values
bool

removePage()

public removePage(TPage $page) : $this
Parameters
$page : TPage
Return values
$this

setActive()

public setActive(bool $active) : $this
Parameters
$active : bool
Return values
$this

setAddToNewPages()

public setAddToNewPages(bool $addToNewPages) : $this
Parameters
$addToNewPages : bool
Return values
$this

setCode()

public setCode(string $code) : $this
Parameters
$code : string
Return values
$this

setCookieCategory()

public setCookieCategory(string $cookieCategory) : $this
Parameters
$cookieCategory : string
Return values
$this

setId()

public setId(int|null $id) : $this
Parameters
$id : int|null
Return values
$this

setInsertTime()

public setInsertTime(DateTime $insertTime) : $this
Parameters
$insertTime : DateTime
Return values
$this

setName()

public setName(string $name) : $this
Parameters
$name : string
Return values
$this

setPages()

public setPages(Collection<int, TPage>|array<int, TPage> $pages) : $this
Parameters
$pages : Collection<int, TPage>|array<int, TPage>
Return values
$this

setPlacement()

public setPlacement(string $placement) : $this
Parameters
$placement : string
Return values
$this

setSort()

public setSort(int $sort) : $this
Parameters
$sort : int
Return values
$this

setType()

public setType(string $type) : $this
Parameters
$type : string
Return values
$this

setUpdateDatetime()

public setUpdateDatetime(DateTime|null $updateDatetime) : $this
Parameters
$updateDatetime : DateTime|null
Return values
$this

getTraitsRecursive()

Walks the trait list recursively and collects nested traits too.

private static getTraitsRecursive(array<string, string> $traits) : array<string, string>
Parameters
$traits : array<string, string>
Return values
array<string, string>
On this page

Search results