Skip to content

Commit

Permalink
[4.x] Add RevisionSaving event (#8551)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell authored Oct 30, 2023
1 parent 5b6c38f commit 5f282ec
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Events/RevisionSaving.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Statamic\Events;

class RevisionSaving extends Event
{
public $revision;

public function __construct($revision)
{
$this->revision = $revision;
}

/**
* Dispatch the event with the given arguments, and halt on first non-null listener response.
*
* @return mixed
*/
public static function dispatch()
{
return event(new static(...func_get_args()), [], true);
}
}
5 changes: 5 additions & 0 deletions src/Revisions/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Statamic\Data\ExistsAsFile;
use Statamic\Events\RevisionDeleted;
use Statamic\Events\RevisionSaved;
use Statamic\Events\RevisionSaving;
use Statamic\Facades;
use Statamic\Facades\Revision as Revisions;
use Statamic\Support\Traits\FluentlyGetsAndSets;
Expand Down Expand Up @@ -130,6 +131,10 @@ public function toArray()

public function save()
{
if (RevisionSaving::dispatch($this) === false) {
return false;
}

Revisions::save($this);

RevisionSaved::dispatch($this);
Expand Down

0 comments on commit 5f282ec

Please sign in to comment.