DraftBehavior ​
- Type
- Class
- Namespace
- craft\behaviors
- Inherits
- craft\behaviors\DraftBehavior » craft\behaviors\BaseRevisionBehavior » yii\base\Behavior » yii\base\BaseObject
- Implements
- yii\base\Configurable
- Since
- 3.2.0
DraftBehavior is applied to element drafts.
Public Properties ​
Property | Description |
---|---|
creator | craft\elements\User, null |
creatorId | integer, null – The creator’s ID |
dateLastMerged | \craft\behaviors\Datetime , null – The date that the canonical element was last merged into this one |
draftName | string – The draft name |
draftNotes | string, null – The draft notes |
isOutdated | boolean |
markAsSaved | boolean – Whether the draft should be marked as saved (if unpublished). |
mergingChanges | boolean – Whether recent changes to the canonical element are being merged into this element |
outdatedAttributes | string[] |
outdatedFields | string[] |
owner | craft\base\ElementInterface |
source | craft\base\ElementInterface, null |
sourceId | integer |
trackChanges | boolean – Whether to track changes in this draft |
dateLastMerged
​
- Type
\craft\behaviors\Datetime
, null- Default value
null
The date that the canonical element was last merged into this one
draftName
​
- Type
- string
- Default value
null
The draft name
draftNotes
​
The draft notes
isOutdated
​
- Type
- boolean
- Default value
null
- Access
- Read-only
- Since
- 3.4.0
markAsSaved
​
- Type
- boolean
- Default value
true
- Since
- 3.6.6
Whether the draft should be marked as saved (if unpublished).
mergingChanges
​
- Type
- boolean
- Default value
null
Whether recent changes to the canonical element are being merged into this element
outdatedAttributes
​
- Type
- string[]
- Default value
null
- Access
- Read-only
- Since
- 3.4.0
outdatedFields
​
- Type
- string[]
- Default value
null
- Access
- Read-only
- Since
- 3.4.0
trackChanges
​
DEPRECATED
Deprecated in 3.7.0.
- Type
- boolean
- Default value
true
Whether to track changes in this draft
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. |
getDateLastMerged() | Returns the date that the canonical element was last merged into this one. |
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. |
getMergingChanges() | Returns whether recent changes to the canonical element are being merged into this element. |
getOutdatedAttributes() | Returns the outdated attributes. |
getOutdatedFields() | Returns the outdated field handles. |
getSource() | Returns the draft/revision’s source element. |
getSourceId() | Returns the draft/revision's source element ID. |
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. |
setCreator() | Sets the draft's creator. |
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',
]
Returns ​
array – Events (array keys) and the corresponding event handler methods (array values).
getDateLastMerged()
​
DEPRECATED
Deprecated in 3.7.0. Use \craft\base\ElementInterface::$dateLastMerged
instead.
- Since
- 3.7.0
Returns the date that the canonical element was last merged into this one.
getDraftName()
​
- Since
- 3.3.17
Returns the draft’s name.
Returns ​
getIsOutdated()
​
DEPRECATED
Deprecated in 3.7.12. Use craft\helpers\ElementHelper::isOutdated() instead.
- Since
- 3.4.0
Returns whether the source element has been saved since the time this draft was created or last merged.
Returns ​
getMergingChanges()
​
DEPRECATED
Deprecated in 3.7.0. Use \craft\base\ElementInterface::$mergingCanonicalChanges
instead.
- Since
- 3.7.0
Returns whether recent changes to the canonical element are being merged into this element.
getOutdatedAttributes()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::getOutdatedAttributes() instead.
- Since
- 3.4.0
Returns the outdated attributes.
Returns ​
string[]
getOutdatedFields()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::getOutdatedFields() instead.
- Since
- 3.4.0
Returns the outdated field handles.
Returns ​
string[]
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.
isAttributeModified()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::isAttributeModified() instead.
- Since
- 3.4.0
Returns whether an attribute has changed on the draft.
Arguments ​
$name
(string)
Returns ​
isAttributeOutdated()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::isAttributeOutdated() instead.
- Since
- 3.4.0
Returns whether an attribute on the draft has fallen behind the source element’s value.
Arguments ​
$name
(string)
Returns ​
isFieldModified()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::isFieldModified() instead.
- Since
- 3.4.0
Returns whether a field value has changed on the draft.
Arguments ​
$fieldHandle
(string)
Returns ​
isFieldOutdated()
​
DEPRECATED
Deprecated in 3.7.0. Use craft\base\ElementInterface::isFieldOutdated() instead.
- Since
- 3.4.0
Returns whether a field value on the draft has fallen behind the source element’s value.
Arguments ​
$fieldHandle
(string)