Skip to content

ElementTrait ​

Type
Trait
Namespace
craft\base
Implemented by
craft\base\Element, craft\elements\Address, craft\elements\Asset, craft\elements\Category, craft\elements\Entry, craft\elements\GlobalSet, craft\elements\Tag, craft\elements\User, craft\test\mockclasses\elements\ExampleElement
Since
3.0.0

ElementTrait implements the common methods and properties for element classes.

View source

Public Properties ​

PropertyDescription
archivedboolean – Whether the element is archived
awaitingFieldValuesboolean – Whether the element is still awaiting its custom field values
dateCreatedDateTime, null – The date that the element was created
dateDeletedDateTime, null – The date that the element was trashed
dateLastMergedDateTime, null – The date that the canonical element was last merged into this one
dateUpdatedDateTime, null – The date that the element was last updated
deletedWithOwnerboolean, null – Whether the element was deleted along with its owner
draftIdinteger, null – The ID of the draft’s row in the drafts table
duplicateOfcraft\base\ElementInterface, null – The element that this element is duplicating.
eagerLoadInfocraft\elements\db\EagerLoadInfo, null – Info about the eager loading setup used to query this element.
elementQueryResultcraft\base\ElementInterface[], null – All elements that the element was queried with.
enabledboolean – Whether the element is enabled
fieldLayoutIdinteger, null – The element’s field layout ID
firstSaveboolean – Whether the element is being saved for the first time in a normal state (not as a draft or revision).
forceSaveboolean – Whether the element should definitely be saved, if it’s a nested element being considered for saving by \craft\base\NestedElementManager.
hardDeleteboolean – Whether the element is being hard-deleted.
idinteger, null – The element’s ID
isNewForSiteboolean – Whether the element is being saved to the current site for the first time.
isProvisionalDraftboolean – Whether this is a provisional draft.
levelinteger, null – The element’s level within its structure
lftinteger, null – The element’s left position within its structure
mergingCanonicalChangesboolean – Whether recent changes to the canonical element are being merged into this element.
newSiteIdsinteger[] – The site IDs that the element was just propagated to for the first time.
previewingboolean – Whether the element is currently being previewed.
propagateAllboolean – Whether all element attributes should be propagated across all its supported sites, even if that means overwriting existing site-specific values.
propagatingboolean – Whether the element is being saved in the context of propagating another site's version of the element.
propagatingFromcraft\base\ElementInterface, null – The element that this element is being propagated from.
resavingboolean – Whether the element is being resaved by a ResaveElement job or a resave console command.
revisionIdinteger, null – The ID of the revision’s row in the revisions table
rgtinteger, null – The element’s right position within its structure
rootinteger, null – The element’s structure’s root ID
searchScoreinteger, null – The element’s search score, if the craft\elements\db\ElementQuery::search() parameter was used when querying for the element
siteIdinteger, null – The site ID the element is associated with
siteSettingsIdinteger, null – The ID of the element’s record in the elements_sites table
slugstring, null – The element’s slug
structureIdinteger, null – The element’s structure ID
tempIdstring, null – The element’s temporary ID (only used if the element’s URI format contains {id})
titlestring, null – The element’s title
trashedboolean – Whether the element has been soft-deleted.
uidstring, null – The element’s UID
updatingFromDerivativeboolean – Whether the element is being updated from a derivative element, such as a draft or revision.
uristring, null – The element’s URI

archived ​

Type
boolean
Default value
false

Whether the element is archived

View source

awaitingFieldValues ​

Type
boolean
Default value
false

Whether the element is still awaiting its custom field values

View source

dateCreated ​

Type
DateTime, null
Default value
null

The date that the element was created

View source

dateDeleted ​

Type
DateTime, null
Default value
null
Since
3.2.0

The date that the element was trashed

View source

dateLastMerged ​

Type
DateTime, null
Default value
null
Since
3.7.0

The date that the canonical element was last merged into this one

View source

dateUpdated ​

Type
DateTime, null
Default value
null

The date that the element was last updated

View source

deletedWithOwner ​

Type
boolean, null
Default value
null
Since
5.0.0

Whether the element was deleted along with its owner

View source

draftId ​

Type
integer, null
Default value
null
Since
3.2.0

The ID of the draft’s row in the drafts table

View source

duplicateOf ​

Type
craft\base\ElementInterface, null
Default value
null

The element that this element is duplicating.

View source

eagerLoadInfo ​

Type
craft\elements\db\EagerLoadInfo, null
Default value
null
Since
5.0.0

Info about the eager loading setup used to query this element.

View source

elementQueryResult ​

Type
craft\base\ElementInterface[], null
Default value
null
Since
5.0.0

All elements that the element was queried with.

View source

enabled ​

Type
boolean
Default value
true

Whether the element is enabled

View source

fieldLayoutId ​

Type
integer, null
Default value
null

The element’s field layout ID

View source

firstSave ​

Type
boolean
Default value
false
Since
3.7.5

Whether the element is being saved for the first time in a normal state (not as a draft or revision).

View source

forceSave ​

Type
boolean
Default value
false
Since
5.0.0

Whether the element should definitely be saved, if it’s a nested element being considered for saving by \craft\base\NestedElementManager.

View source

hardDelete ​

Type
boolean
Default value
false
Since
3.2.0

Whether the element is being hard-deleted.

View source

id ​

Type
integer, null
Default value
null

The element’s ID

View source

isNewForSite ​

Type
boolean
Default value
false
Since
3.7.15

Whether the element is being saved to the current site for the first time.

View source

isProvisionalDraft ​

Type
boolean
Default value
false
Since
3.7.0

Whether this is a provisional draft.

View source

level ​

Type
integer, null
Default value
null

The element’s level within its structure

View source

lft ​

Type
integer, null
Default value
null

The element’s left position within its structure

View source

mergingCanonicalChanges ​

Type
boolean
Default value
false
Since
3.7.0

Whether recent changes to the canonical element are being merged into this element.

View source

newSiteIds ​

Type
integer[]
Default value
[]
Since
3.2.9

The site IDs that the element was just propagated to for the first time.

View source

previewing ​

Type
boolean
Default value
false
Since
3.2.0

Whether the element is currently being previewed.

View source

propagateAll ​

Type
boolean
Default value
false
Since
3.2.0

Whether all element attributes should be propagated across all its supported sites, even if that means overwriting existing site-specific values.

View source

propagating ​

Type
boolean
Default value
false

Whether the element is being saved in the context of propagating another site's version of the element.

View source

propagatingFrom ​

Type
craft\base\ElementInterface, null
Default value
null
Since
5.0.0

The element that this element is being propagated from.

View source

resaving ​

Type
boolean
Default value
false
Since
3.1.22

Whether the element is being resaved by a ResaveElement job or a resave console command.

View source

revisionId ​

Type
integer, null
Default value
null
Since
3.2.0

The ID of the revision’s row in the revisions table

View source

rgt ​

Type
integer, null
Default value
null

The element’s right position within its structure

View source

root ​

Type
integer, null
Default value
null

The element’s structure’s root ID

View source

searchScore ​

Type
integer, null
Default value
null

The element’s search score, if the craft\elements\db\ElementQuery::search() parameter was used when querying for the element

View source

siteId ​

Type
integer, null
Default value
null

The site ID the element is associated with

View source

siteSettingsId ​

Type
integer, null
Default value
null
Since
3.5.2

The ID of the element’s record in the elements_sites table

View source

slug ​

Type
string, null
Default value
null

The element’s slug

View source

structureId ​

Type
integer, null
Default value
null

The element’s structure ID

View source

tempId ​

Type
string, null
Default value
null

The element’s temporary ID (only used if the element’s URI format contains {id})

View source

title ​

Type
string, null
Default value
null

The element’s title

View source

trashed ​

Type
boolean
Default value
false

Whether the element has been soft-deleted.

View source

uid ​

Type
string, null
Default value
null

The element’s UID

View source

updatingFromDerivative ​

Type
boolean
Default value
false
Since
3.7.0

Whether the element is being updated from a derivative element, such as a draft or revision.

If this is true, the derivative element can be accessed via duplicateOf.

View source

uri ​

Type
string, null
Default value
null

The element’s URI

View source