mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 00:37:02 +02:00
Add Pages::savePageOrFieldReady() and Pages::savedPageOrField() hooks per request
This commit is contained in:
@@ -61,6 +61,8 @@
|
||||
* @method unpublished(Page $page) Hook called after a published page has just been unpublished.
|
||||
* @method saveFieldReady(Page $page, Field $field) Hook called just before a saveField() method saves a page fied.
|
||||
* @method savedField(Page $page, Field $field) Hook called after saveField() method successfully executes.
|
||||
* @method saveEitherReady(Page $page, $fieldName = '') Hook inclusive of both saveReady() and saveFieldReady().
|
||||
* @method savedEither(Page $page, array $changes) Hook inclusive of both saved() and savedField().
|
||||
* @method found(PageArray $pages, array $details) Hook called at the end of a $pages->find().
|
||||
*
|
||||
* TO-DO
|
||||
@@ -1585,6 +1587,28 @@ class Pages extends Wire {
|
||||
$this->log("Saved page field '$field->name'", $page);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called when either of Pages::save or Pages::saveField is ready to execute
|
||||
*
|
||||
* #pw-hooker
|
||||
*
|
||||
* @param Page $page
|
||||
* @param string $fieldName Populated only if call originates from saveField
|
||||
*
|
||||
*/
|
||||
public function ___savePageOrFieldReady(Page $page, $fieldName = '') { }
|
||||
|
||||
/**
|
||||
* Hook called after either of Pages::save or Pages::saveField successfully executes
|
||||
*
|
||||
* #pw-hooker
|
||||
*
|
||||
* @param Page $page
|
||||
* @param array $changes Names of fields
|
||||
*
|
||||
*/
|
||||
public function ___savedPageOrField(Page $page, array $changes = array()) { }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@@ -504,7 +504,12 @@ class PagesEditor extends Wire {
|
||||
$systemVersion = $config->systemVersion;
|
||||
if(!$page->created_users_id) $page->created_users_id = $userID;
|
||||
if($page->isChanged('status') && empty($options['noHooks'])) $this->pages->statusChangeReady($page);
|
||||
$extraData = empty($options['noHooks']) ? $this->pages->saveReady($page) : array();
|
||||
if(empty($options['noHooks'])) {
|
||||
$extraData = $this->pages->saveReady($page);
|
||||
$this->pages->savePageOrFieldReady($page);
|
||||
} else {
|
||||
$extraData = array();
|
||||
}
|
||||
$sql = '';
|
||||
|
||||
if(strpos($page->name, $this->untitledPageName) === 0) $this->pages->setupPageName($page);
|
||||
@@ -659,7 +664,10 @@ class PagesEditor extends Wire {
|
||||
// if page hasn't changed, don't continue further
|
||||
if(!$page->isChanged() && !$isNew) {
|
||||
$this->pages->debugLog('save', '[not-changed]', true);
|
||||
if(empty($options['noHooks'])) $this->pages->saved($page, array());
|
||||
if(empty($options['noHooks'])) {
|
||||
$this->pages->saved($page, array());
|
||||
$this->pages->savedPageOrField($page, array());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -744,6 +752,7 @@ class PagesEditor extends Wire {
|
||||
// trigger hooks
|
||||
if(empty($options['noHooks'])) {
|
||||
$this->pages->saved($page, $changes, $changesValues);
|
||||
$this->pages->savedPageOrField($page, $changes);
|
||||
if($triggerAddedPage) $this->pages->added($triggerAddedPage);
|
||||
if($page->namePrevious && $page->namePrevious != $page->name) $this->pages->renamed($page);
|
||||
if($page->parentPrevious) $this->pages->moved($page);
|
||||
@@ -799,7 +808,10 @@ class PagesEditor extends Wire {
|
||||
if($value instanceof Pagefiles || $value instanceof Pagefile) $page->filesManager()->save();
|
||||
$page->trackChange($field->name);
|
||||
|
||||
if(empty($options['noHooks'])) $this->pages->saveFieldReady($page, $field);
|
||||
if(empty($options['noHooks'])) {
|
||||
$this->pages->saveFieldReady($page, $field);
|
||||
$this->pages->savePageOrFieldReady($page, $field->name);
|
||||
}
|
||||
|
||||
if($field->type->savePageField($page, $field)) {
|
||||
$page->untrackChange($field->name);
|
||||
@@ -813,7 +825,10 @@ class PagesEditor extends Wire {
|
||||
$database->execute($query);
|
||||
}
|
||||
$return = true;
|
||||
if(empty($options['noHooks'])) $this->pages->savedField($page, $field);
|
||||
if(empty($options['noHooks'])) {
|
||||
$this->pages->savedField($page, $field);
|
||||
$this->pages->savedPageOrField($page, array($field->name));
|
||||
}
|
||||
} else {
|
||||
$return = false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user