CustomAsset
extends BaseEntity
in package
implements
IdentifiableInterface
uses
IdentifiableTrait, PageCollectionTrait
Custom code: a library of code snippets inserted into website pages (`cms_system_custom_assets`).
Lets an administrator without server file access add a style or a measurement script.
It did not fit into cms_system_settings (value is varchar(255)), hence an own table.
The code is a library: a page runs exactly the snippets assigned to it (association PageCollectionTrait::$pages), nothing more, nothing less. There is no site-wide mode: a snippet assigned to no page runs nowhere.
Columns decide what happens to the code:
typeCustomAssetType: what the code is wrapped in (<style>,<script>, nothing)placementCustomAssetPlacement: where in the pagecookieCategory: whether to wait for cookie consent; category key fromconfig/Shared/cookieConsent.neon(CookieConsentConfig)addToNewPages: a newly created page gets this snippet assigned automatically (hook PageManager)
IMPORTANT: the content is intentionally not sanitized. That is the whole point of the
screen, and the author holds the privilege :Admin:System:CustomAsset:edit (assigning to
pages additionally :Admin:System:CustomAsset:assign), granted separately (inserting JS is
effectively full control of the page). The front end only wraps the code in a tag and
prints it with |noescape; the only safeguard is removing the closing tag that would let
the code break out of <style>/<script>
(CustomAssets::wrap()).
NOTE: no @template on purpose: the concrete page class is determined by #[CollectionOf]
in each branch separately. A generic parameter would force @extends/@return annotations
on all setters (PHPStan missingType.generics) and bring only a type nobody reads.
Attributes
- #[MappedSuperclass]
- #[TableAlias]
- $alias: 'customAsset'
Table of Contents
Interfaces
- IdentifiableInterface
- Entity with a simple integer primary key. Most entities have one (often via {@see \App\Core\Traits\Shared\Models\Entities\IdentifiableTrait}); texts and links with a composite key do not, which is why `getId()` is not on {@see \App\Core\Base\BaseEntity}. Code that needs the id of a generic entity asks for this interface (parameter type, template bound, `instanceof`).
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<int, BaseEntity>
- $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'
$name
protected
string
$name
= ''
Attributes
- #[Column]
- $name: 'name'
- $type: 'string'
- $length: 255
$pages
protected
Collection<int, BaseEntity>
$pages
= new ArrayCollection()
$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
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
$thiscallInitMethods()
Calls `init{TraitName}()` for every used trait that defines such a method.
public
callInitMethods() : void
getActive()
public
getActive() : bool
Return values
boolgetAddToNewPages()
public
getAddToNewPages() : bool
Return values
boolgetAllTraits()
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
stringgetCookieCategory()
public
getCookieCategory() : string
Return values
stringgetId()
public
getId() : int|null
Return values
int|nullgetInsertTime()
public
getInsertTime() : DateTime
Return values
DateTimegetName()
public
getName() : string
Return values
stringgetPage()
public
getPage(int $pageId) : TPage|null
Parameters
- $pageId : int
Return values
TPage|nullgetPages()
public
getPages() : Collection<int, TPage>
Return values
Collection<int, TPage>getPlacement()
public
getPlacement() : string
Return values
stringgetPlacementEnum()
public
getPlacementEnum() : CustomAssetPlacement|null
Return values
CustomAssetPlacement|nullgetSort()
public
getSort() : int
Return values
intgetType()
public
getType() : string
Return values
stringgetTypeEnum()
public
getTypeEnum() : CustomAssetType|null
Return values
CustomAssetType|nullgetUpdateDatetime()
public
getUpdateDatetime() : DateTime|null
Return values
DateTime|nullisActive()
public
isActive() : bool
Return values
boolisAddToNewPages()
public
isAddToNewPages() : bool
Return values
boolisPersisted()
public
isPersisted() : bool
Return values
boolneedsCookieConsent()
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
boolpageCollectionInit()
public
pageCollectionInit() : void
removePage()
public
removePage(TPage $page) : $this
Parameters
- $page : TPage
Return values
$thissetActive()
public
setActive(bool $active) : $this
Parameters
- $active : bool
Return values
$thissetAddToNewPages()
public
setAddToNewPages(bool $addToNewPages) : $this
Parameters
- $addToNewPages : bool
Return values
$thissetCode()
public
setCode(string $code) : $this
Parameters
- $code : string
Return values
$thissetCookieCategory()
public
setCookieCategory(string $cookieCategory) : $this
Parameters
- $cookieCategory : string
Return values
$thissetId()
public
setId(int|null $id) : $this
Parameters
- $id : int|null
Return values
$thissetInsertTime()
public
setInsertTime(DateTime $insertTime) : $this
Parameters
- $insertTime : DateTime
Return values
$thissetName()
public
setName(string $name) : $this
Parameters
- $name : string
Return values
$thissetPages()
public
setPages(Collection<int, TPage>|array<int, TPage> $pages) : $this
Parameters
- $pages : Collection<int, TPage>|array<int, TPage>
Return values
$thissetPlacement()
public
setPlacement(string $placement) : $this
Parameters
- $placement : string
Return values
$thissetSort()
public
setSort(int $sort) : $this
Parameters
- $sort : int
Return values
$thissetType()
public
setType(string $type) : $this
Parameters
- $type : string
Return values
$thissetUpdateDatetime()
public
setUpdateDatetime(DateTime|null $updateDatetime) : $this
Parameters
- $updateDatetime : DateTime|null
Return values
$thisgetTraitsRecursive()
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>