Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

APICHANGE: add_extension() is now called directly on the class, inste…

…ad of on Object
  • Loading branch information...
commit fdea5321c7208a56eea53308338057e84ad7a14f 1 parent 96a4080
@ajoneil ajoneil authored halkyon committed
View
10 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;
}
View
4 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);
}
}
}
View
4 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 `<ul>` you created earlier in `zzz_admin/admin/templates/LeftAndMain.ss`
View
4 docs/en/reference/dataextension.md
@@ -31,14 +31,14 @@ ForumRole extension to the `[api:Member]` object.
:::php
- Object::add_extension('Class You Want To Override', 'Your Class Name');
+ ClassYouWantToOverride::add_extension('Your Class Name');
For example above we want to override Member with a Custom Member so we would write the following
:::php
// add to mysite/_config.php
- Object::add_extension('Member', 'CustomMember');
+ Member::add_extension('CustomMember');
## Implementation
View
2  docs/en/reference/member.md
@@ -91,7 +91,7 @@ Using inheritance to add extra behaviour or data fields to a member is limiting,
class. A better way is to use role extensions to add this behaviour.
:::php
- Object::add_extension('Member', 'ForumRole');
+ Member::add_extension('ForumRole');
// OR
Member::add_role('ForumRole');
View
2  docs/en/reference/modeladmin.md
@@ -198,7 +198,7 @@ also another tool at your disposal: The `[api:Extension]` API.
}
// mysite/_config.php
- Object::add_extension('MyAdmin', 'MyAdminExtension');
+ MyAdmin::add_extension('MyAdminExtension');
The following extension points are available: `updateEditForm()`, `updateSearchContext()`,
`updateSearchForm()`, `updateList()`, `updateImportForm`.
View
2  docs/en/reference/siteconfig.md
@@ -51,7 +51,7 @@ Create a mysite/code/CustomSiteConfig.php file.
Then add a link to your extension in the _config.php file like below.
- Object::add_extension('SiteConfig', 'CustomSiteConfig');
+ SiteConfig::add_extension('CustomSiteConfig');
This tells SilverStripe to add the CustomSiteConfig extension to the `[api:SiteConfig]` class.
View
2  docs/en/topics/rich-text-editing.md
@@ -85,7 +85,7 @@ Example: Remove field for "image captions"
:::php
// File: mysite/_config.php
- Object::add_extension('HtmlEditorField', 'MyToolbarExtension');
+ HtmlEditorField::add_extension('MyToolbarExtension');
Adding functionality is a bit more advanced, you'll most likely
need to add some fields to the PHP forms, as well as write some
View
2  docs/en/topics/versioning.md
@@ -24,7 +24,7 @@ which map to different database tables.
:::php
// mysite/_config.php
- Object::add_extension('MyRecord', 'Versioned("Stage","Live")');
+ MyRecord::add_extension('Versioned("Stage","Live")');
Note: The extension is automatically applied to `SiteTree` class.
View
6 search/FulltextSearchable.php
@@ -32,7 +32,7 @@ class FulltextSearchable extends DataExtension {
* It can be used to limit the searched classes, but not to add your own classes.
* For this purpose, please use {@link Object::add_extension()} directly:
* <code>
- * Object::add_extension('MyObject', "FulltextSearchable('MySearchableField,'MyOtherField')");
+ * MyObject::add_extension("FulltextSearchable('MySearchableField,'MyOtherField')");
* </code>
*
* Caution: This is a wrapper method that should only be used in _config.php,
@@ -53,7 +53,7 @@ public static function enable($searchableClasses = array('SiteTree', 'File')) {
if(isset($defaultColumns[$class])) {
Config::inst()->update($class, 'create_table_options', array('MySQLDatabase' => 'ENGINE=MyISAM'));
- Object::add_extension($class, "FulltextSearchable('{$defaultColumns[$class]}')");
+ $class::add_extension("FulltextSearchable('{$defaultColumns[$class]}')");
} else {
throw new Exception(
"FulltextSearchable::enable() I don't know the default search columns for class '$class'");
@@ -61,7 +61,7 @@ public static function enable($searchableClasses = array('SiteTree', 'File')) {
}
self::$searchable_classes = $searchableClasses;
if(class_exists("ContentController")){
- Object::add_extension("ContentController", "ContentControllerSearchExtension");
+ ContentController::add_extension("ContentControllerSearchExtension");
}
}
View
4 tests/core/ObjectTest.php
@@ -228,7 +228,7 @@ public function testHasAndAddExtension() {
);
// ObjectTest_ExtendTest3 is added manually
- Object::add_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest3("Param")');
+ ObjectTest_ExtensionTest::add_extension('ObjectTest_ExtendTest3("Param")');
$this->assertTrue(
Object::has_extension('ObjectTest_ExtensionTest', 'ObjectTest_ExtendTest3'),
"Extensions are detected with static has_extension() when added through add_extension()"
@@ -247,7 +247,7 @@ public function testHasAndAddExtension() {
public function testRemoveExtension() {
// manually add ObjectTest_ExtendTest2
- Object::add_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2');
+ ObjectTest_ExtensionRemoveTest::add_extension('ObjectTest_ExtendTest2');
$this->assertTrue(
Object::has_extension('ObjectTest_ExtensionRemoveTest', 'ObjectTest_ExtendTest2'),
"Extension added through \$add_extension() are added correctly"
View
2  tests/forms/FormScaffolderTest.php
@@ -147,4 +147,4 @@ public function updateCMSFields(FieldList $fields) {
}
-DataObject::add_extension('FormScaffolderTest_Article', 'FormScaffolderTest_ArticleExtension');
+FormScaffolderTest_Article::add_extension('FormScaffolderTest_ArticleExtension');
View
10 tests/model/DataExtensionTest.php
@@ -75,7 +75,7 @@ public function testManyManyAssociationWithExtension() {
*/
public function testAddExtensionLoadsStatics() {
// Object::add_extension() will load DOD statics directly, so let's try adding a extension on the fly
- Object::add_extension('DataExtensionTest_Player', 'DataExtensionTest_PlayerExtension');
+ DataExtensionTest_Player::add_extension('DataExtensionTest_PlayerExtension');
// Now that we've just added the extension, we need to rebuild the database
$this->resetDBSchema(true);
@@ -226,7 +226,7 @@ class DataExtensionTest_RelatedObject extends DataObject implements TestOnly {
}
-DataObject::add_extension('DataExtensionTest_Member', 'DataExtensionTest_ContactRole');
+DataExtensionTest_Member::add_extension('DataExtensionTest_ContactRole');
class DataExtensionTest_MyObject extends DataObject implements TestOnly {
@@ -305,7 +305,7 @@ public function testMethodApplied() {
}
-DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext1');
-DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext2');
-DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Faves');
+DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext1');
+DataExtensionTest_MyObject::add_extension('DataExtensionTest_Ext2');
+DataExtensionTest_MyObject::add_extension('DataExtensionTest_Faves');
View
2  tests/model/DataObjectTest.php
@@ -1313,5 +1313,5 @@ class DataObjectTest_TeamComment extends DataObject {
);
}
-DataObject::add_extension('DataObjectTest_Team', 'DataObjectTest_Team_Extension');
+DataObjectTest_Team::add_extension('DataObjectTest_Team_Extension');
View
2  tests/search/FulltextSearchableTest.php
@@ -18,7 +18,7 @@ public function setUp() {
public function tearDown() {
// TODO This shouldn't need all arguments included
if($this->orig['File_searchable']) {
- Object::add_extension('File', 'FulltextSearchable(\'"Filename","Title","Content"\')');
+ File::add_extension('FulltextSearchable(\'"Filename","Title","Content"\')');
}
parent::tearDown();
View
8 tests/security/MemberTest.php
@@ -470,7 +470,7 @@ public function testExtendedCan() {
$this->assertFalse($member->canEdit());
/* Apply a extension that allows viewing in any case (most likely the case for member profiles) */
- Object::add_extension('Member', 'MemberTest_ViewingAllowedExtension');
+ Member::add_extension('MemberTest_ViewingAllowedExtension');
$member2 = $this->objFromFixture('Member', 'staffmember');
$this->assertTrue($member2->canView());
@@ -479,7 +479,7 @@ public function testExtendedCan() {
/* Apply a extension that denies viewing of the Member */
Object::remove_extension('Member', 'MemberTest_ViewingAllowedExtension');
- Object::add_extension('Member', 'MemberTest_ViewingDeniedExtension');
+ Member::add_extension('MemberTest_ViewingDeniedExtension');
$member3 = $this->objFromFixture('Member', 'managementmember');
$this->assertFalse($member3->canView());
@@ -488,7 +488,7 @@ public function testExtendedCan() {
/* Apply a extension that allows viewing and editing but denies deletion */
Object::remove_extension('Member', 'MemberTest_ViewingDeniedExtension');
- Object::add_extension('Member', 'MemberTest_EditingAllowedDeletingDeniedExtension');
+ Member::add_extension('MemberTest_EditingAllowedDeletingDeniedExtension');
$member4 = $this->objFromFixture('Member', 'accountingmember');
$this->assertTrue($member4->canView());
@@ -603,7 +603,7 @@ public function testMap_in_groupsReturnsAdmins() {
*/
protected function addExtensions($extensions) {
if($extensions) foreach($extensions as $extension) {
- Object::add_extension('Member', $extension);
+ Member::add_extension($extension);
}
return $extensions;
}
Please sign in to comment.
Something went wrong with that request. Please try again.