From fdea5321c7208a56eea53308338057e84ad7a14f Mon Sep 17 00:00:00 2001 From: Andrew O'Neil Date: Tue, 9 Oct 2012 16:55:37 +1300 Subject: [PATCH] APICHANGE: add_extension() is now called directly on the class, instead of on Object --- core/Object.php | 10 +++++++++- dev/SapphireTest.php | 4 ++-- docs/en/howto/extend-cms-interface.md | 4 ++-- docs/en/reference/dataextension.md | 4 ++-- docs/en/reference/member.md | 2 +- docs/en/reference/modeladmin.md | 2 +- docs/en/reference/siteconfig.md | 2 +- docs/en/topics/rich-text-editing.md | 2 +- docs/en/topics/versioning.md | 2 +- search/FulltextSearchable.php | 6 +++--- tests/core/ObjectTest.php | 4 ++-- tests/forms/FormScaffolderTest.php | 2 +- tests/model/DataExtensionTest.php | 10 +++++----- tests/model/DataObjectTest.php | 2 +- tests/search/FulltextSearchableTest.php | 2 +- tests/security/MemberTest.php | 8 ++++---- 16 files changed, 37 insertions(+), 29 deletions(-) diff --git a/core/Object.php b/core/Object.php index 63ee46b1c31..a473be80951 100755 --- a/core/Object.php +++ b/core/Object.php @@ -450,7 +450,15 @@ public static function has_extension($class, $requiredExtension) { * @param string $extension Subclass of {@link Extension} with optional parameters * as a string, e.g. "Versioned" or "Translatable('Param')" */ - public static function add_extension($class, $extension) { + public static function add_extension($extension) { + $class = get_called_class(); + + if(func_num_args() > 1) { + Deprecation::notice('3.1.0', "Object::add_extension() deprecated. Call add_extension() on the class"); + $class = func_get_arg(0); + $extension = func_get_arg(1); + } + if(!preg_match('/^([^(]*)/', $extension, $matches)) { return false; } diff --git a/dev/SapphireTest.php b/dev/SapphireTest.php index 58fd711333a..a9678210676 100644 --- a/dev/SapphireTest.php +++ b/dev/SapphireTest.php @@ -291,7 +291,7 @@ public function setUpOnce() { if(!Object::has_extension($class, $extension)) { if(!isset($this->extensionsToRemove[$class])) $this->extensionsToReapply[$class] = array(); $this->extensionsToRemove[$class][] = $extension; - Object::add_extension($class, $extension); + $class::add_extension($extension); $isAltered = true; } } @@ -326,7 +326,7 @@ public function tearDownOnce() { // Reapply ones removed foreach($this->extensionsToReapply as $class => $extensions) { foreach($extensions as $extension) { - Object::add_extension($class, $extension); + $class::add_extension($extension); } } } diff --git a/docs/en/howto/extend-cms-interface.md b/docs/en/howto/extend-cms-interface.md index c48059dcb6f..d530a9bf7c4 100644 --- a/docs/en/howto/extend-cms-interface.md +++ b/docs/en/howto/extend-cms-interface.md @@ -97,7 +97,7 @@ Create a new file called `zzz_admin/code/BookmarkedPageExtension.php` and insert Enable the extension with the following line in `zzz_mysite/_config.php`: :::php - Object::add_extension('SiteTree', 'BookmarkedPageExtension'); + SiteTree::add_extension('BookmarkedPageExtension'); In order to add the field to the database, run a `dev/build/?flush=all`. Refresh the CMS, open a page for editing and you should see the new checkbox. @@ -121,7 +121,7 @@ Add the following code to a new file `zzz_admin/code/BookmarkedLeftAndMainExtens Enable the extension with the following line in `zzz_mysite/_config.php`: :::php - Object::add_extension('LeftAndMain', 'BookmarkedPagesLeftAndMainExtension'); + LeftAndMain::add_extension('BookmarkedPagesLeftAndMainExtension'); As the last step, replace the hardcoded links with our list from the database. Find the `