Permalink
Browse files

ENHANCEMENT Remove use of deprecated extraStatics in core files

  • Loading branch information...
1 parent 926daa2 commit 4cf8db3ee41dbefb7299295dd9180f99e2fc2ee2 @halkyon halkyon committed Apr 18, 2012
View
@@ -52,7 +52,7 @@ function __construct() {
* @static
* @param $class
*/
- static function add_to_class($class, $extensionClass, $args) {
+ static function add_to_class($class, $extensionClass, $args = null) {
Config::add_static_source($class, $extensionClass);
}
View
@@ -1,6 +1,6 @@
<?php
/**
- * An extension that adds additional functionality to a {@link DataObject}.
+ An extension that adds additional functionality to a {@link DataObject}.
*
* @package framework
* @subpackage model
@@ -18,20 +18,19 @@
* @var array
*/
protected static $extendable_statics = array(
- 'db' => true,
+ 'db' => true,
'has_one' => true,
'belongs_to' => true,
- 'indexes' => true,
- 'defaults' => true,
- 'has_many' => true,
- 'many_many' => true,
- 'belongs_many_many' => true,
+ 'indexes' => true,
+ 'defaults' => true,
+ 'has_many' => true,
+ 'many_many' => true,
+ 'belongs_many_many' => true,
'many_many_extraFields' => true,
'searchable_fields' => true,
'api_access' => false,
);
-
static function add_to_class($class, $extensionClass, $args = null) {
if(method_exists($class, 'extraDBFields')) {
$extraStaticsMethod = 'extraDBFields';
@@ -185,12 +184,12 @@ function updateCMSActions(FieldList $actions) {
* by the extension
* By default, the summaryField() of its owner will merge more fields defined in the extension's
* $extra_fields['summary_fields']
+ *
+ * @param array $fields Array of field names
*/
- function updateSummaryFields(&$fields){
- $extra_fields = $this->extraStatics();
- if(isset($extra_fields['summary_fields'])){
- $summary_fields = $extra_fields['summary_fields'];
-
+ function updateSummaryFields(&$fields) {
+ $summary_fields = Config::inst()->get($this->class, 'summary_fields');
+ if($summary_fields) {
// if summary_fields were passed in numeric array,
// convert to an associative array
if($summary_fields && array_key_exists(0, $summary_fields)) {
@@ -199,26 +198,21 @@ function updateSummaryFields(&$fields){
if($summary_fields) $fields = array_merge($fields, $summary_fields);
}
}
-
+
/**
* this function is used to provide modifications to the fields labels in CMS
* by the extension
* By default, the fieldLabels() of its owner will merge more fields defined in the extension's
* $extra_fields['field_labels']
+ *
+ * @param array $labels Array of field labels
*/
- function updateFieldLabels(&$lables){
- $extra_fields = $this->extraStatics();
- if(isset($extra_fields['field_labels'])){
- $field_labels = $extra_fields['field_labels'];
- if($field_labels) $lables = array_merge($lables, $field_labels);
+ function updateFieldLabels(&$labels) {
+ $field_labels = Config::inst()->get($this->class, 'field_labels');
+ if($field_labels) {
+ $labels = array_merge($labels, $field_labels);
}
}
-
- /**
- * Clear any internal caches.
- */
- function flushCache() {
- }
}
@@ -612,34 +612,32 @@ function tearDown() {
class UploadFieldTest_Record extends DataObject implements TestOnly {
-static $db = array(
- 'Title' => 'Text',
-);
+ static $db = array(
+ 'Title' => 'Text',
+ );
-static $has_one = array(
- 'HasOneFile' => 'File',
- 'HasOneFileMaxOne' => 'File',
- 'HasOneFileMaxTwo' => 'File',
-);
+ static $has_one = array(
+ 'HasOneFile' => 'File',
+ 'HasOneFileMaxOne' => 'File',
+ 'HasOneFileMaxTwo' => 'File',
+ );
-static $has_many = array(
- 'HasManyFiles' => 'File',
- 'HasManyFilesMaxTwo' => 'File',
-);
+ static $has_many = array(
+ 'HasManyFiles' => 'File',
+ 'HasManyFilesMaxTwo' => 'File',
+ );
-static $many_many = array(
- 'ManyManyFiles' => 'File',
-);
+ static $many_many = array(
+ 'ManyManyFiles' => 'File',
+ );
}
class UploadFieldTest_FileExtension extends DataExtension implements TestOnly {
- function extraStatics($class = null, $extension = null) {
- return array(
- 'has_one' => array('Record' => 'UploadFieldTest_Record')
- );
- }
+ public static $has_one = array(
+ 'Record' => 'UploadFieldTest_Record'
+ );
function canDelete($member = null) {
if($this->owner->Name == 'nodelete.txt') return false;
@@ -1,10 +1,8 @@
<?php
class i18nTestModuleExtension extends DataExtension {
- function extraStatics($class=null, $extension=null) {
- return array(
- 'db' => array(
- 'MyExtraField' => 'Varchar'
- )
- );
- }
+
+ public static $db = array(
+ 'MyExtraField' => 'Varchar'
+ );
+
}
@@ -177,7 +177,7 @@ class DataExtensionTest_Player extends DataObject implements TestOnly {
class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnly {
- function extraStatics($class=null, $extension=null) {
+ public static function add_to_class($class = null, $extensionClass = null, $args = null) {
// Only add these extensions if the $class is set to DataExtensionTest_Player, to
// test that the argument works.
if($class == 'DataExtensionTest_Player') {
@@ -197,23 +197,21 @@ function extraStatics($class=null, $extension=null) {
}
class DataExtensionTest_ContactRole extends DataExtension implements TestOnly {
-
- function extraStatics($class=null, $extension=null) {
- return array(
- 'db' => array(
- 'Website' => 'Varchar',
- 'Phone' => 'Varchar(255)',
- ),
- 'has_many' => array(
- 'RelatedObjects' => 'DataExtensionTest_RelatedObject'
- ),
- 'defaults' => array(
- 'Phone' => '123'
- ),
- 'api_access' => true,
- );
- }
-
+
+ public static $db =array(
+ 'db' => array(
+ 'Website' => 'Varchar',
+ 'Phone' => 'Varchar(255)',
+ ),
+ 'has_many' => array(
+ 'RelatedObjects' => 'DataExtensionTest_RelatedObject'
+ ),
+ 'defaults' => array(
+ 'Phone' => '123'
+ ),
+ 'api_access' => true,
+ );
+
}
class DataExtensionTest_RelatedObject extends DataObject implements TestOnly {
@@ -293,19 +291,19 @@ function canThree($member = null) {
}
class DataExtensionTest_Faves extends DataExtension implements TestOnly {
- public function extraStatics($class=null, $extension=null) {
- return array(
- 'many_many' => array(
- 'Faves' => 'DataExtensionTest_RelatedObject'
- )
- );
- }
+
+ public static $many_many = array(
+ 'Faves' => 'DataExtensionTest_RelatedObject'
+ );
+
}
class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly {
+
public function testMethodApplied() {
return "hello world";
}
+
}
DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext1');

0 comments on commit 4cf8db3

Please sign in to comment.