DraftBehavior

Type
Class
Namespace
craft\behaviors
Inherits
craft\behaviors\DraftBehavior » craft\behaviors\BaseRevisionBehavior » yii\base\Behavior (opens new window) » yii\base\BaseObject (opens new window)
Implements
yii\base\Configurable (opens new window)
Since
3.2.0

DraftBehavior is applied to element drafts.

View source (opens new window)

# Public Properties

# dateLastMerged

Type
DateTime (opens new window), null (opens new window)
Default value
false

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

View source (opens new window)

# draftName

Type
string (opens new window)
Default value
null

The draft name

View source (opens new window)

# draftNotes

Type
string (opens new window), null (opens new window)
Default value
null

The draft notes

View source (opens new window)

# isOutdated

Type
boolean (opens new window)
Default value
null
Access
Read-only
Since
3.4.0

View source (opens new window)

# mergingChanges

Type
boolean (opens new window)
Default value
false
Since
3.4.0

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

View source (opens new window)

# outdatedAttributes

Type
string (opens new window)[]
Default value
null
Access
Read-only
Since
3.4.0

View source (opens new window)

# outdatedFields

Type
string (opens new window)[]
Default value
null
Access
Read-only
Since
3.4.0

View source (opens new window)

# trackChanges

Type
boolean (opens new window)
Default value
false

Whether to track changes in this draft

View source (opens new window)

# Public Methods

Method Description
__call() (opens new window) Calls the named method which is not a class method.
__construct() (opens new window) Constructor.
__get() (opens new window) Returns the value of an object property.
__isset() (opens new window) Checks if a property is set, i.e. defined and not null.
__set() (opens new window) Sets value of an object property.
__unset() (opens new window) Sets an object property to null.
attach() (opens new window) Attaches the behavior object to the component.
canGetProperty() (opens new window) Returns a value indicating whether a property can be read.
canSetProperty() (opens new window) Returns a value indicating whether a property can be set.
className() (opens new window) Returns the fully qualified name of this class.
detach() (opens new window) Detaches the behavior object from the component.
events() Declares event handlers for the owner (opens new window)'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/revision’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() (opens new window) Returns a value indicating whether a method is defined.
hasProperty() (opens new window) 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.
setCreator() Sets the draft's creator.

# events()

Declares event handlers for the owner (opens new window)'s events.

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

The callbacks will be attached to the owner (opens new window)'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 (opens new window)

Returns

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

# getDraftName()

Since
3.3.17

Returns the draft’s name.

View source (opens new window)

Returns

string (opens new window)

# 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 (opens new window)

Returns

boolean (opens new window)

# getOutdatedAttributes()

Since
3.4.0

Returns the outdated attributes.

View source (opens new window)

Returns

string (opens new window)[]

# getOutdatedFields()

Since
3.4.0

Returns the outdated field handles.

View source (opens new window)

Returns

string (opens new window)[]

# handleDelete()

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

View source (opens new window)

# handleSave()

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

View source (opens new window)

# 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 (opens new window)

# isAttributeModified()

Since
3.4.0

Returns whether an attribute has changed on the draft.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isAttributeOutdated()

Since
3.4.0

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isFieldModified()

Since
3.4.0

Returns whether a field value has changed on the draft.

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# isFieldOutdated()

Since
3.4.0

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

View source (opens new window)

Arguments

Returns

boolean (opens new window)

# Protected Methods

Method Description
source() Returns the source element.