API CHANGE: Renamed SiteTreeDecorator to SiteTreeExtension.

MINOR: Replaced references to decorators with extensions.
This commit is contained in:
ajshort 2011-04-15 19:37:15 +10:00
parent 446b8bae63
commit 6462c59f0f
13 changed files with 84 additions and 69 deletions

View File

@ -29,4 +29,4 @@ else SS_Report::register('ReportAdmin', 'BrokenLinksReport',-20);
*/ */
ShortcodeParser::get('default')->register('sitetree_link', array('SiteTree', 'link_shortcode_handler')); ShortcodeParser::get('default')->register('sitetree_link', array('SiteTree', 'link_shortcode_handler'));
Object::add_extension('File', 'SiteTreeFileDecorator'); Object::add_extension('File', 'SiteTreeFileExtension');

View File

@ -614,7 +614,7 @@ JS;
} }
/** /**
* @uses LeftAndMainDecorator->augmentNewSiteTreeItem() * @uses LeftAndMainExtension->augmentNewSiteTreeItem()
*/ */
public function getNewItem($id, $setID = true) { public function getNewItem($id, $setID = true) {
list($dummy, $className, $parentID, $suffix) = array_pad(explode('-',$id),4,null); list($dummy, $className, $parentID, $suffix) = array_pad(explode('-',$id),4,null);

View File

@ -174,7 +174,7 @@ class ModelAsController extends Controller implements NestedController {
$record = $query->execute()->first(); $record = $query->execute()->first();
if($record && ($oldPage = DataObject::get_by_id('SiteTree', $record['RecordID']))) { if($record && ($oldPage = DataObject::get_by_id('SiteTree', $record['RecordID']))) {
// Run the page through an extra filter to ensure that all decorators are applied. // Run the page through an extra filter to ensure that all extensions are applied.
if(SiteTree::get_by_link($oldPage->RelativeLink())) return $oldPage; if(SiteTree::get_by_link($oldPage->RelativeLink())) return $oldPage;
} }
} }

View File

@ -37,7 +37,7 @@ class SiteConfig extends DataObject implements PermissionProvider {
/** /**
* Get the fields that are sent to the CMS. In * Get the fields that are sent to the CMS. In
* your decorators: updateCMSFields(&$fields) * your extensions: updateCMSFields($fields)
* *
* @return Fieldset * @return Fieldset
*/ */
@ -125,7 +125,7 @@ class SiteConfig extends DataObject implements PermissionProvider {
/** /**
* Get the actions that are sent to the CMS. In * Get the actions that are sent to the CMS. In
* your decorators: updateEditFormActions(&$actions) * your extensions: updateEditFormActions($actions)
* *
* @return Fieldset * @return Fieldset
*/ */

View File

@ -234,8 +234,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* If you have enabled {@link SiteTree::nested_urls()} on this site, then you can use a nested link such as * If you have enabled {@link SiteTree::nested_urls()} on this site, then you can use a nested link such as
* "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link. * "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link.
* *
* Note that if no model can be found, this method will fall over to a decorated alternateGetByLink method provided * Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided
* by a decorator attached to {@link SiteTree} * by a extension attached to {@link SiteTree}
* *
* @param string $link * @param string $link
* @param bool $cache * @param bool $cache
@ -261,7 +261,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return ($pages->Count() == 1) ? $pages->First() : null; return ($pages->Count() == 1) ? $pages->First() : null;
} }
// Attempt to grab an alternative page from decorators. // Attempt to grab an alternative page from extensions.
if(!$sitetree) { if(!$sitetree) {
$parentID = self::nested_urls() ? 0 : null; $parentID = self::nested_urls() ? 0 : null;
@ -668,7 +668,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* *
* Returns true if the member is allowed to do the given action. * Returns true if the member is allowed to do the given action.
* *
* @uses DataObjectDecorator->can() * @uses DataExtension->can()
* *
* If a page is set to inherit, but has no parent, it inherits from * If a page is set to inherit, but has no parent, it inherits from
* {@link SiteConfig} * {@link SiteConfig}
@ -707,11 +707,11 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - alternateCanAddChildren() on a decorator returns FALSE * - alternateCanAddChildren() on a extension returns FALSE
* - canEdit() is not granted * - canEdit() is not granted
* - There are no classes defined in {@link $allowed_children} * - There are no classes defined in {@link $allowed_children}
* *
* @uses SiteTreeDecorator->canAddChildren() * @uses SiteTreeExtension->canAddChildren()
* @uses canEdit() * @uses canEdit()
* @uses $allowed_children * @uses $allowed_children
* *
@ -724,7 +724,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($member && Permission::checkMember($member, "ADMIN")) return true; if($member && Permission::checkMember($member, "ADMIN")) return true;
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canAddChildren', $member); $extended = $this->extendedCan('canAddChildren', $member);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -738,12 +738,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - canView() on any decorator returns FALSE * - canView() on any extension returns FALSE
* - "CanViewType" directive is set to "Inherit" and any parent page return false for canView() * - "CanViewType" directive is set to "Inherit" and any parent page return false for canView()
* - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in * - "CanViewType" directive is set to "LoggedInUsers" and no user is logged in
* - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups * - "CanViewType" directive is set to "OnlyTheseUsers" and user is not in the given groups
* *
* @uses DataObjectDecorator->canView() * @uses DataExtension->canView()
* @uses ViewerGroups() * @uses ViewerGroups()
* *
* @return boolean True if the current user can view this page. * @return boolean True if the current user can view this page.
@ -756,7 +756,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
// admin override // admin override
if($member && Permission::checkMember($member, array("ADMIN", "SITETREE_VIEW_ALL"))) return true; if($member && Permission::checkMember($member, array("ADMIN", "SITETREE_VIEW_ALL"))) return true;
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canView', $member); $extended = $this->extendedCan('canView', $member);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -813,12 +813,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - canDelete() returns FALSE on any decorator * - canDelete() returns FALSE on any extension
* - canEdit() returns FALSE * - canEdit() returns FALSE
* - any descendant page returns FALSE for canDelete() * - any descendant page returns FALSE for canDelete()
* *
* @uses canDelete() * @uses canDelete()
* @uses DataObjectDecorator->canDelete() * @uses SiteTreeExtension->canDelete()
* @uses canEdit() * @uses canEdit()
* *
* @param Member $member * @param Member $member
@ -833,7 +833,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
return true; return true;
} }
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canDelete', $memberID); $extended = $this->extendedCan('canDelete', $memberID);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -856,13 +856,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - canCreate() returns FALSE on any decorator * - canCreate() returns FALSE on any extension
* - $can_create is set to FALSE and the site is not in "dev mode" * - $can_create is set to FALSE and the site is not in "dev mode"
* *
* Use {@link canAddChildren()} to control behaviour of creating children under this page. * Use {@link canAddChildren()} to control behaviour of creating children under this page.
* *
* @uses $can_create * @uses $can_create
* @uses DataObjectDecorator->canCreate() * @uses DataExtension->canCreate()
* *
* @param Member $member * @param Member $member
* @return boolean True if the current user can create pages on this class. * @return boolean True if the current user can create pages on this class.
@ -874,7 +874,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($member && Permission::checkMember($member, "ADMIN")) return true; if($member && Permission::checkMember($member, "ADMIN")) return true;
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canCreate', $member); $extended = $this->extendedCan('canCreate', $member);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -888,7 +888,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - canEdit() on any decorator returns FALSE * - canEdit() on any extension returns FALSE
* - canView() return false * - canView() return false
* - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit() * - "CanEditType" directive is set to "Inherit" and any parent page return false for canEdit()
* - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the CMS_Access_CMSMAIN permission code * - "CanEditType" directive is set to "LoggedInUsers" and no user is logged in or doesn't have the CMS_Access_CMSMAIN permission code
@ -896,7 +896,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* *
* @uses canView() * @uses canView()
* @uses EditorGroups() * @uses EditorGroups()
* @uses DataObjectDecorator->canEdit() * @uses DataExtension->canEdit()
* *
* @param Member $member Set to FALSE if you want to explicitly test permissions without a valid user (useful for unit tests) * @param Member $member Set to FALSE if you want to explicitly test permissions without a valid user (useful for unit tests)
* @return boolean True if the current user can edit this page. * @return boolean True if the current user can edit this page.
@ -908,7 +908,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($memberID && Permission::checkMember($memberID, array("ADMIN", "SITETREE_EDIT_ALL"))) return true; if($memberID && Permission::checkMember($memberID, array("ADMIN", "SITETREE_EDIT_ALL"))) return true;
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canEdit', $memberID); $extended = $this->extendedCan('canEdit', $memberID);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -937,10 +937,10 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* application. * application.
* *
* Denies permission if any of the following conditions is TRUE: * Denies permission if any of the following conditions is TRUE:
* - canPublish() on any decorator returns FALSE * - canPublish() on any extension returns FALSE
* - canEdit() returns FALSE * - canEdit() returns FALSE
* *
* @uses SiteTreeDecorator->canPublish() * @uses SiteTreeExtension->canPublish()
* *
* @param Member $member * @param Member $member
* @return boolean True if the current user can publish this page. * @return boolean True if the current user can publish this page.
@ -950,7 +950,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
if($member && Permission::checkMember($member, "ADMIN")) return true; if($member && Permission::checkMember($member, "ADMIN")) return true;
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canPublish', $member); $extended = $this->extendedCan('canPublish', $member);
if($extended !== null) return $extended; if($extended !== null) return $extended;
@ -959,7 +959,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
} }
public function canDeleteFromLive($member = null) { public function canDeleteFromLive($member = null) {
// Standard mechanism for accepting permission changes from decorators // Standard mechanism for accepting permission changes from extensions
$extended = $this->extendedCan('canDeleteFromLive', $member); $extended = $this->extendedCan('canDeleteFromLive', $member);
if($extended !==null) return $extended; if($extended !==null) return $extended;
@ -1512,7 +1512,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
* If {@link Extension}s wish to alter URL segment generation, they can do so by defining * If {@link Extension}s wish to alter URL segment generation, they can do so by defining
* updateURLSegment(&$url, $title). $url will be passed by reference and should be modified. * updateURLSegment(&$url, $title). $url will be passed by reference and should be modified.
* $title will contain the title that was originally used as the source of this generated URL. * $title will contain the title that was originally used as the source of this generated URL.
* This lets decorators either start from scratch, or incrementally modify the generated URL. * This lets extensions either start from scratch, or incrementally modify the generated URL.
* *
* @param string $title Page title. * @param string $title Page title.
* @return string Generated url segment * @return string Generated url segment
@ -1524,7 +1524,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$t = "page-$this->ID"; $t = "page-$this->ID";
} }
// Hook for decorators // Hook for extensions
$this->extend('updateURLSegment', $t, $title); $this->extend('updateURLSegment', $t, $title);
return $t; return $t;
@ -1952,7 +1952,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$actions->push(new FormAction('email', _t('CMSMain.EMAIL', 'Email'))); $actions->push(new FormAction('email', _t('CMSMain.EMAIL', 'Email')));
$actions->push(new FormAction('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version'))); $actions->push(new FormAction('rollback', _t('CMSMain.ROLLBACK', 'Roll back to this version')));
// getCMSActions() can be extended with updateCMSActions() on a decorator // getCMSActions() can be extended with updateCMSActions() on a extension
$this->extend('updateCMSActions', $actions); $this->extend('updateCMSActions', $actions);
return $actions; return $actions;
@ -2006,7 +2006,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$actions->push(new FormAction('publish', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save and Publish'))); $actions->push(new FormAction('publish', _t('SiteTree.BUTTONSAVEPUBLISH', 'Save and Publish')));
} }
// getCMSActions() can be extended with updateCMSActions() on a decorator // getCMSActions() can be extended with updateCMSActions() on a extension
$this->extend('updateCMSActions', $actions); $this->extend('updateCMSActions', $actions);
return $actions; return $actions;
@ -2015,8 +2015,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/** /**
* Publish this page. * Publish this page.
* *
* @uses SiteTreeDecorator->onBeforePublish() * @uses SiteTreeExtension->onBeforePublish()
* @uses SiteTreeDecorator->onAfterPublish() * @uses SiteTreeExtension->onAfterPublish()
*/ */
function doPublish() { function doPublish() {
if (!$this->canPublish()) return false; if (!$this->canPublish()) return false;
@ -2024,7 +2024,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
$original = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $this->ID"); $original = Versioned::get_one_by_stage("SiteTree", "Live", "\"SiteTree\".\"ID\" = $this->ID");
if(!$original) $original = new SiteTree(); if(!$original) $original = new SiteTree();
// Handle activities undertaken by decorators // Handle activities undertaken by extensions
$this->invokeWithExtensions('onBeforePublish', $original); $this->invokeWithExtensions('onBeforePublish', $original);
//$this->PublishedByID = Member::currentUser()->ID; //$this->PublishedByID = Member::currentUser()->ID;
$this->write(); $this->write();
@ -2062,7 +2062,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
} else { if (file_exists(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php')) unlink(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php'); } } else { if (file_exists(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php')) unlink(BASE_PATH.'/'.ASSETS_DIR.'/_homepage-map.php'); }
} }
// Handle activities undertaken by decorators // Handle activities undertaken by extensions
$this->invokeWithExtensions('onAfterPublish', $original); $this->invokeWithExtensions('onAfterPublish', $original);
return true; return true;
@ -2082,8 +2082,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/** /**
* Unpublish this page - remove it from the live site * Unpublish this page - remove it from the live site
* *
* @uses SiteTreeDecorator->onBeforeUnpublish() * @uses SiteTreeExtension->onBeforeUnpublish()
* @uses SiteTreeDecorator->onAfterUnpublish() * @uses SiteTreeExtension->onAfterUnpublish()
*/ */
function doUnpublish() { function doUnpublish() {
if(!$this->canDeleteFromLive()) return false; if(!$this->canDeleteFromLive()) return false;
@ -2500,7 +2500,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
/** /**
* Stops extendCMSFields() being called on getCMSFields(). * Stops extendCMSFields() being called on getCMSFields().
* This is useful when you need access to fields added by subclasses * This is useful when you need access to fields added by subclasses
* of SiteTree in a decorator. Call before calling parent::getCMSFields(), * of SiteTree in a extension. Call before calling parent::getCMSFields(),
* and reenable afterwards. * and reenable afterwards.
*/ */
public static function disableCMSFieldsExtensions() { public static function disableCMSFieldsExtensions() {

View File

@ -1,31 +1,17 @@
<?php <?php
/** /**
* Plug-ins for additional functionality in your SiteTree classes. * @package cms
*
* @package cms
* @subpackage model * @subpackage model
* @deprecated 3.0 Use {@link SiteTreeExtension}.
*/ */
abstract class SiteTreeDecorator extends DataObjectDecorator { abstract class SiteTreeDecorator extends SiteTreeExtension {
function onBeforePublish(&$original) { public function __construct() {
user_error(
'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.',
E_USER_NOTICE
);
parent::__construct();
} }
function onAfterPublish(&$original) { }
}
function onBeforeUnpublish() {
}
function onAfterUnpublish() {
}
function canAddChildren($member) {
}
function canPublish($member) {
}
}
?>

View File

@ -0,0 +1,29 @@
<?php
/**
* Plug-ins for additional functionality in your SiteTree classes.
*
* @package cms
* @subpackage model
*/
abstract class SiteTreeExtension extends DataExtension {
function onBeforePublish(&$original) {
}
function onAfterPublish(&$original) {
}
function onBeforeUnpublish() {
}
function onAfterUnpublish() {
}
function canAddChildren($member) {
}
function canPublish($member) {
}
}

View File

@ -3,7 +3,7 @@
* @package cms * @package cms
* @subpackage model * @subpackage model
*/ */
class SiteTreeFileDecorator extends DataObjectDecorator { class SiteTreeFileExtension extends DataExtension {
function extraStatics() { function extraStatics() {
return array( return array(

View File

@ -1,5 +1,5 @@
<?php <?php
class SiteTreeFolderDecorator extends DataObjectDecorator { class SiteTreeFolderExtension extends DataExtension {
function updateCMSFields(&$fields) { function updateCMSFields(&$fields) {
// TODO commenting out unused files tab till bugs are fixed // TODO commenting out unused files tab till bugs are fixed

View File

@ -199,7 +199,7 @@ class SS_Report extends ViewableData {
} }
function getCMSActions() { function getCMSActions() {
// getCMSActions() can be extended with updateCMSActions() on a decorator // getCMSActions() can be extended with updateCMSActions() on a extension
$actions = new FieldSet(); $actions = new FieldSet();
$this->extend('updateCMSActions', $actions); $this->extend('updateCMSActions', $actions);
return $actions; return $actions;

View File

@ -3,7 +3,7 @@
* @package cms * @package cms
* @subpackage publishers * @subpackage publishers
*/ */
abstract class StaticPublisher extends DataObjectDecorator { abstract class StaticPublisher extends DataExtension {
/** /**
* Defines whether to output information about publishing or not. By * Defines whether to output information about publishing or not. By
* default, this is off, and should be turned on when you want debugging * default, this is off, and should be turned on when you want debugging

View File

@ -242,7 +242,7 @@ class SiteTreeBacklinksTest extends SapphireTest {
} }
class SiteTreeBacklinksTest_DOD extends DataObjectDecorator implements TestOnly { class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly {
function extraStatics() { function extraStatics() {
return array( return array(
'db' => array( 'db' => array(

View File

@ -27,7 +27,7 @@ class SiteTreeTest extends SapphireTest {
// overwrite locale // overwrite locale
Translatable::set_default_locale("en_US"); Translatable::set_default_locale("en_US");
// refresh the decorated statics - different fields in $db with Translatable enabled // refresh the extended statics - different fields in $db with Translatable enabled
if(self::$origTranslatableSettings['has_extension']) { if(self::$origTranslatableSettings['has_extension']) {
Object::remove_extension('SiteTree', 'Translatable'); Object::remove_extension('SiteTree', 'Translatable');
Object::remove_extension('SiteConfig', 'Translatable'); Object::remove_extension('SiteConfig', 'Translatable');