DraftBehavior

Type
Class
Namespace
craft\behaviors
Inherits
craft\behaviors\DraftBehavior » yii\base\Behavior » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.2.0

DraftBehavior is applied to element drafts.

View source

# Public Properties

Property Description
creator craft\elements\User, null
creatorId integer, null – The draft creator’s ID
dateLastMerged DateTime, null – The last date that this draft was merged with changes from the source element
draftName string – The draft name
draftNotes string, null – The draft notes
isOutdated boolean
mergingChanges boolean – Whether the source element’s changes are currently being merged into the draft.
outdatedAttributes string[]
outdatedFields string[]
owner yii\base\Component, null – The owner of this behavior
source craft\base\ElementInterface, null
sourceId integer, null – The source element’s ID
trackChanges boolean – Whether to track changes in this draft

# creator

Type
craft\elements\User, null
Access
Read-only

View source

# creatorId

Type
integer, null

The draft creator’s ID

View source

# dateLastMerged

Type
DateTime, null

The last date that this draft was merged with changes from the source element

View source

# draftName

Type
string

The draft name

View source

# draftNotes

Type
string, null

The draft notes

View source

# isOutdated

Type
boolean
Access
Read-only
Since
3.4.0

View source

# mergingChanges

Type
boolean
Since
3.4.0

Whether the source element’s changes are currently being merged into the draft.

View source

# outdatedAttributes

Type
string[]
Access
Read-only
Since
3.4.0

View source

# outdatedFields

Type
string[]
Access
Read-only
Since
3.4.0

View source

# source

Type
craft\base\ElementInterface, null
Access
Read-only

View source

# sourceId

Type
integer, null

The source element’s ID

View source

# trackChanges

Type
boolean

Whether to track changes in this draft

View source

# Public Methods

Method Description
__call() Calls the named method which is not a class method.
__construct() Constructor.
__get() Returns the value of an object property.
__isset() Checks if a property is set, i.e. defined and not null.
__set() Sets value of an object property.
__unset() Sets an object property to null.
attach() Attaches the behavior object to the component.
canGetProperty() Returns a value indicating whether a property can be read.
canSetProperty() Returns a value indicating whether a property can be set.
className() Returns the fully qualified name of this class.
detach() Detaches the behavior object from the component.
events() Declares event handlers for the owner's events.
getCreator() Returns the draft’s creator.
getDraftName() Returns the draft’s name.
getIsOutdated() Returns whether the source element has been saved since the time this draft was created or last merged.
getOutdatedAttributes() Returns the outdated attributes.
getOutdatedFields() Returns the outdated field handles.
getSource() Returns the draft’s source element.
handleDelete() Deletes the row in the drafts table after the draft element is deleted.
handleSave() Updates the row in the drafts table after the draft element is saved.
hasMethod() Returns a value indicating whether a method is defined.
hasProperty() Returns a value indicating whether a property is defined.
init() Initializes the object.
isAttributeModified() Returns whether an attribute has changed on the draft.
isAttributeOutdated() Returns whether an attribute on the draft has fallen behind the source element’s value.
isFieldModified() Returns whether a field value has changed on the draft.
isFieldOutdated() Returns whether a field value on the draft has fallen behind the source element’s value.

# events()

Declares event handlers for the owner's events.

Child classes may override this method to declare what PHP callbacks should be attached to the events of the owner component.

The callbacks will be attached to the owner's events when the behavior is attached to the owner; and they will be detached from the events when the behavior is detached from the component.

The callbacks can be any of the following:

  • method in this behavior: 'handleClick', equivalent to [$this, 'handleClick']
  • object method: [$object, 'handleClick']
  • static method: ['Page', 'handleClick']
  • anonymous function: function ($event) { ... }

The following is an example:

[
    Model::EVENT_BEFORE_VALIDATE => 'myBeforeValidate',
    Model::EVENT_AFTER_VALIDATE => 'myAfterValidate',
]

View source

Returns

array – Events (array keys) and the corresponding event handler methods (array values).

# getCreator()

Returns the draft’s creator.

View source

Returns

craft\elements\User, null

# getDraftName()

Since
3.3.17

Returns the draft’s name.

View source

Returns

string

# getIsOutdated()

Since
3.4.0

Returns whether the source element has been saved since the time this draft was created or last merged.

View source

Returns

boolean

# getOutdatedAttributes()

Since
3.4.0

Returns the outdated attributes.

View source

Returns

string[]

# getOutdatedFields()

Since
3.4.0

Returns the outdated field handles.

View source

Returns

string[]

# getSource()

DEPRECATED

Deprecated in 3.2.9. Use craft\helpers\ElementHelper::sourceElement() instead.

Returns the draft’s source element.

View source

Returns

craft\base\ElementInterface, null

# handleDelete()

Deletes the row in the drafts table after the draft element is deleted.

View source

# handleSave()

Updates the row in the drafts table after the draft element is saved.

View source

# init()

Initializes the object.

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

View source

# isAttributeModified()

Since
3.4.0

Returns whether an attribute has changed on the draft.

View source

Arguments

Returns

boolean

# isAttributeOutdated()

Since
3.4.0

Returns whether an attribute on the draft has fallen behind the source element’s value.

View source

Arguments

Returns

boolean

# isFieldModified()

Since
3.4.0

Returns whether a field value has changed on the draft.

View source

Arguments

Returns

boolean

# isFieldOutdated()

Since
3.4.0

Returns whether a field value on the draft has fallen behind the source element’s value.

View source

Arguments

Returns

boolean