EntryRevisions

Type
Class
Namespace
craft\services
Inherits
craft\services\EntryRevisions » yii\base\Component » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0

Entry Revisions service.

An instance of the Entry Revisions service is globally accessible in Craft via Craft::$app->entryRevisions.

View source

Public Properties

PropertyDescription
$behaviorsyii\base\Behavior – List of behaviors attached to this component

Public Methods

MethodDescription
__call()Calls the named method which is not a class method.
__clone()This method is called after the object is created by cloning an existing one.
__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.
attachBehavior()Attaches a behavior to this component.
attachBehaviors()Attaches a list of behaviors to the component.
behaviors()Returns a list of behaviors that this component should behave as.
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.
deleteDraft()Deletes a draft by it's model.
detachBehavior()Detaches a behavior from the component.
detachBehaviors()Detaches all behaviors from the component.
doesEntryHaveVersions()Returns whether an entry has any versions stored.
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.
getBehavior()Returns the named behavior object.
getBehaviors()Returns all behaviors attached to this component.
getDraftById()Returns a draft by its ID.
getDraftsByEntryId()Returns drafts of a given entry.
getEditableDraftsByEntryId()Returns the drafts of a given entry that are editable by the current user.
getVersionById()Returns a version by its ID.
getVersionsByEntryId()Returns versions by an entry ID.
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.
hasMethod()Returns a value indicating whether a method is defined.
hasProperty()Returns a value indicating whether a property is defined.
init()Initializes the object.
off()Detaches an existing event handler from this component.
on()Attaches an event handler to an event.
publishDraft()Publishes a draft.
revertEntryToVersion()Reverts an entry to a version.
saveDraft()Saves a draft.
saveVersion()Saves a new version.
trigger()Triggers an event.

deleteDraft()

Deletes a draft by it's model.

View source

Arguments

Returns

boolean – Whether the draft was deleted successfully

Signature

public boolean deleteDraft ( craft\models\EntryDraft $draft )

doesEntryHaveVersions()

Returns whether an entry has any versions stored.

View source

Arguments

  • $entryId (integer) – The entry ID to search for
  • $siteId (integer, null) – The site ID to search for

Returns

boolean

Signature

public boolean doesEntryHaveVersions ( \craft\services\int $entryId, \craft\services\int $siteId = null )

getDraftById()

Returns a draft by its ID.

View source

Arguments

Returns

craft\models\EntryDraft, null

Signature

public craft\models\EntryDraft, null getDraftById ( \craft\services\int $draftId )

getDraftsByEntryId()

Returns drafts of a given entry.

View source

Arguments

  • $entryId (integer)
  • $siteId (integer, null)
  • $withContent (boolean) – Whether the field content should be included on the drafts

Returns

craft\models\EntryDraft[]

Signature

public craft\models\EntryDraft[] getDraftsByEntryId ( \craft\services\int $entryId, \craft\services\int $siteId = null, \craft\services\bool $withContent = false )

getEditableDraftsByEntryId()

Returns the drafts of a given entry that are editable by the current user.

View source

Arguments

Returns

craft\models\EntryDraft[]

Signature

public craft\models\EntryDraft[] getEditableDraftsByEntryId ( \craft\services\int $entryId, \craft\services\int $siteId = null )

getVersionById()

Returns a version by its ID.

View source

Arguments

Returns

craft\models\EntryVersion, null

Signature

public craft\models\EntryVersion, null getVersionById ( \craft\services\int $versionId )

getVersionsByEntryId()

Returns versions by an entry ID.

View source

Arguments

  • $entryId (integer) – The entry ID to search for.
  • $siteId (integer, null) – The site ID to search for.
  • $limit (integer, null) – The limit on the number of versions to retrieve.
  • $includeCurrent (boolean) – Whether to include the current "top" version of the entry.
  • $withContent (boolean) – Whether the field content should be included on the versions

Returns

craft\models\EntryVersion[]

Signature

public craft\models\EntryVersion[] getVersionsByEntryId ( \craft\services\int $entryId, \craft\services\int $siteId = null, \craft\services\int $limit = null, \craft\services\bool $includeCurrent = false, \craft\services\bool $withContent = false )

publishDraft()

Publishes a draft.

View source

Arguments

Returns

boolean

Signature

public boolean publishDraft ( craft\models\EntryDraft $draft, \craft\services\bool $runValidation = true )

revertEntryToVersion()

Reverts an entry to a version.

View source

Arguments

Returns

boolean

Signature

public boolean revertEntryToVersion ( craft\models\EntryVersion $version, \craft\services\bool $runValidation = true )

saveDraft()

Saves a draft.

View source

Arguments

Returns

boolean

Signature

public boolean saveDraft ( craft\models\EntryDraft $draft, \craft\services\bool $runValidation = true )

saveVersion()

Saves a new version.

View source

Arguments

Returns

boolean

Signature

public boolean saveVersion ( craft\elements\Entry $entry )

Protected Methods

MethodDescription
compareRevisionData()Compares two revisions' data and returns whether it has changed.

compareRevisionData()

Compares two revisions' data and returns whether it has changed.

View source

Arguments

Returns

boolean – Whether it looks like something has changed

Signature

protected boolean compareRevisionData ( array $revisionA, array $revisionB )

Events

EVENT_AFTER_DELETE_DRAFT

Type
craft\events\DraftEvent

The event that is triggered after a draft is deleted.

EVENT_AFTER_PUBLISH_DRAFT

Type
craft\events\DraftEvent

The event that is triggered after a draft is published.

EVENT_AFTER_REVERT_ENTRY_TO_VERSION

Type
craft\events\VersionEvent

The event that is triggered after an entry is reverted to an old version.

EVENT_AFTER_SAVE_DRAFT

Type
craft\events\DraftEvent

The event that is triggered after a draft is saved.

EVENT_BEFORE_DELETE_DRAFT

Type
craft\events\DraftEvent

The event that is triggered before a draft is deleted.

EVENT_BEFORE_PUBLISH_DRAFT

Type
craft\events\DraftEvent

The event that is triggered before a draft is published.

EVENT_BEFORE_REVERT_ENTRY_TO_VERSION

Type
craft\events\VersionEvent

The event that is triggered before an entry is reverted to an old version.

EVENT_BEFORE_SAVE_DRAFT

Type
craft\events\DraftEvent

The event that is triggered before a draft is saved.