SiteTree on*() callbacks now consistently invoke on subclasses as well

Before this was only possible for some specific ones, like onBeforeWrite.
This excludes any callbacks with augment*() or update*() naming,
since these are assumed to be on extension only, with a corresponding
base method available on the class itself (e.g. "updateCMSFields()"
vs "getCMSFields()").
This commit is contained in:
Ingo Schommer 2013-02-05 23:28:50 +01:00
parent fbfc939fc4
commit b19a82b693

View File

@ -577,14 +577,14 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$page = parent::duplicate(false);
$page->Sort = 0;
$this->extend('onBeforeDuplicate', $page);
$this->invokeWithExtensions('onBeforeDuplicate', $page);
if($doWrite) {
$page->write();
$page = $this->duplicateManyManyRelations($this, $page);
}
$this->extend('onAfterDuplicate', $page);
$this->invokeWithExtensions('onAfterDuplicate', $page);
return $page;
}
@ -1653,7 +1653,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($table == 'SiteTree_Live') {
$publishedClass = $origPublished['ClassName'];
$origPublishedObj = new $publishedClass($origPublished);
$this->extend('onRenameLinkedAsset', $origPublishedObj);
$this->invokeWithExtensions('onRenameLinkedAsset', $origPublishedObj);
}
}
}
@ -2262,7 +2262,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if(!$this->canDeleteFromLive()) return false;
if(!$this->ID) return false;
$this->extend('onBeforeUnpublish');
$this->invokeWithExtensions('onBeforeUnpublish', $this);
$origStage = Versioned::current_stage();
Versioned::reading_stage('Live');
@ -2292,7 +2292,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$this->write();
}
$this->extend('onAfterUnpublish');
$this->invokeWithExtensions('onAfterUnpublish', $this);
return true;
}
@ -2301,6 +2301,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* Revert the draft changes: replace the draft content with the content on live
*/
public function doRevertToLive() {
$this->invokeWithExtensions('onBeforeRevertToLive', $this);
$this->publish("Live", "Stage", false);
// Use a clone to get the updates made by $this->publish
@ -2313,7 +2315,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$page->write();
}
$this->extend('onAfterRevertToLive');
$this->invokeWithExtensions('onAfterRevertToLive', $this);
}
/**