Merge pull request #344 from halkyon/remove_deprecated_extrastatics_usage

ENHANCEMENT Remove use of deprecated extraStatics in core files
This commit is contained in:
Ingo Schommer 2012-04-18 15:42:51 -07:00
commit a1327faae4
5 changed files with 66 additions and 78 deletions

View File

@ -52,7 +52,7 @@ abstract class Extension {
* @static * @static
* @param $class * @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); Config::add_static_source($class, $extensionClass);
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/** /**
* An extension that adds additional functionality to a {@link DataObject}. An extension that adds additional functionality to a {@link DataObject}.
* *
* @package framework * @package framework
* @subpackage model * @subpackage model
@ -18,20 +18,19 @@ abstract class DataExtension extends Extension {
* @var array * @var array
*/ */
protected static $extendable_statics = array( protected static $extendable_statics = array(
'db' => true, 'db' => true,
'has_one' => true, 'has_one' => true,
'belongs_to' => true, 'belongs_to' => true,
'indexes' => true, 'indexes' => true,
'defaults' => true, 'defaults' => true,
'has_many' => true, 'has_many' => true,
'many_many' => true, 'many_many' => true,
'belongs_many_many' => true, 'belongs_many_many' => true,
'many_many_extraFields' => true, 'many_many_extraFields' => true,
'searchable_fields' => true, 'searchable_fields' => true,
'api_access' => false, 'api_access' => false,
); );
static function add_to_class($class, $extensionClass, $args = null) { static function add_to_class($class, $extensionClass, $args = null) {
if(method_exists($class, 'extraDBFields')) { if(method_exists($class, 'extraDBFields')) {
$extraStaticsMethod = 'extraDBFields'; $extraStaticsMethod = 'extraDBFields';
@ -185,12 +184,12 @@ abstract class DataExtension extends Extension {
* by the extension * by the extension
* By default, the summaryField() of its owner will merge more fields defined in the extension's * By default, the summaryField() of its owner will merge more fields defined in the extension's
* $extra_fields['summary_fields'] * $extra_fields['summary_fields']
*
* @param array $fields Array of field names
*/ */
function updateSummaryFields(&$fields){ function updateSummaryFields(&$fields) {
$extra_fields = $this->extraStatics(); $summary_fields = Config::inst()->get($this->class, 'summary_fields');
if(isset($extra_fields['summary_fields'])){ if($summary_fields) {
$summary_fields = $extra_fields['summary_fields'];
// if summary_fields were passed in numeric array, // if summary_fields were passed in numeric array,
// convert to an associative array // convert to an associative array
if($summary_fields && array_key_exists(0, $summary_fields)) { if($summary_fields && array_key_exists(0, $summary_fields)) {
@ -199,26 +198,21 @@ abstract class DataExtension extends Extension {
if($summary_fields) $fields = array_merge($fields, $summary_fields); if($summary_fields) $fields = array_merge($fields, $summary_fields);
} }
} }
/** /**
* this function is used to provide modifications to the fields labels in CMS * this function is used to provide modifications to the fields labels in CMS
* by the extension * by the extension
* By default, the fieldLabels() of its owner will merge more fields defined in the extension's * By default, the fieldLabels() of its owner will merge more fields defined in the extension's
* $extra_fields['field_labels'] * $extra_fields['field_labels']
*
* @param array $labels Array of field labels
*/ */
function updateFieldLabels(&$lables){ function updateFieldLabels(&$labels) {
$extra_fields = $this->extraStatics(); $field_labels = Config::inst()->get($this->class, 'field_labels');
if(isset($extra_fields['field_labels'])){ if($field_labels) {
$field_labels = $extra_fields['field_labels']; $labels = array_merge($labels, $field_labels);
if($field_labels) $lables = array_merge($lables, $field_labels);
} }
} }
/**
* Clear any internal caches.
*/
function flushCache() {
}
} }

View File

@ -612,34 +612,32 @@
class UploadFieldTest_Record extends DataObject implements TestOnly { class UploadFieldTest_Record extends DataObject implements TestOnly {
static $db = array( static $db = array(
'Title' => 'Text', 'Title' => 'Text',
); );
static $has_one = array( static $has_one = array(
'HasOneFile' => 'File', 'HasOneFile' => 'File',
'HasOneFileMaxOne' => 'File', 'HasOneFileMaxOne' => 'File',
'HasOneFileMaxTwo' => 'File', 'HasOneFileMaxTwo' => 'File',
); );
static $has_many = array( static $has_many = array(
'HasManyFiles' => 'File', 'HasManyFiles' => 'File',
'HasManyFilesMaxTwo' => 'File', 'HasManyFilesMaxTwo' => 'File',
); );
static $many_many = array( static $many_many = array(
'ManyManyFiles' => 'File', 'ManyManyFiles' => 'File',
); );
} }
class UploadFieldTest_FileExtension extends DataExtension implements TestOnly { class UploadFieldTest_FileExtension extends DataExtension implements TestOnly {
function extraStatics($class = null, $extension = null) { public static $has_one = array(
return array( 'Record' => 'UploadFieldTest_Record'
'has_one' => array('Record' => 'UploadFieldTest_Record') );
);
}
function canDelete($member = null) { function canDelete($member = null) {
if($this->owner->Name == 'nodelete.txt') return false; if($this->owner->Name == 'nodelete.txt') return false;

View File

@ -1,10 +1,8 @@
<?php <?php
class i18nTestModuleExtension extends DataExtension { class i18nTestModuleExtension extends DataExtension {
function extraStatics($class=null, $extension=null) {
return array( public static $db = array(
'db' => array( 'MyExtraField' => 'Varchar'
'MyExtraField' => 'Varchar' );
)
);
}
} }

View File

@ -177,7 +177,7 @@ class DataExtensionTest_Player extends DataObject implements TestOnly {
class DataExtensionTest_PlayerExtension extends DataExtension 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 // Only add these extensions if the $class is set to DataExtensionTest_Player, to
// test that the argument works. // test that the argument works.
if($class == 'DataExtensionTest_Player') { if($class == 'DataExtensionTest_Player') {
@ -197,23 +197,21 @@ class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnl
} }
class DataExtensionTest_ContactRole extends DataExtension implements TestOnly { class DataExtensionTest_ContactRole extends DataExtension implements TestOnly {
function extraStatics($class=null, $extension=null) { public static $db =array(
return array( 'db' => array(
'db' => array( 'Website' => 'Varchar',
'Website' => 'Varchar', 'Phone' => 'Varchar(255)',
'Phone' => 'Varchar(255)', ),
), 'has_many' => array(
'has_many' => array( 'RelatedObjects' => 'DataExtensionTest_RelatedObject'
'RelatedObjects' => 'DataExtensionTest_RelatedObject' ),
), 'defaults' => array(
'defaults' => array( 'Phone' => '123'
'Phone' => '123' ),
), 'api_access' => true,
'api_access' => true, );
);
}
} }
class DataExtensionTest_RelatedObject extends DataObject implements TestOnly { class DataExtensionTest_RelatedObject extends DataObject implements TestOnly {
@ -293,19 +291,19 @@ class DataExtensionTest_Ext2 extends DataExtension implements TestOnly {
} }
class DataExtensionTest_Faves extends DataExtension implements TestOnly { class DataExtensionTest_Faves extends DataExtension implements TestOnly {
public function extraStatics($class=null, $extension=null) {
return array( public static $many_many = array(
'many_many' => array( 'Faves' => 'DataExtensionTest_RelatedObject'
'Faves' => 'DataExtensionTest_RelatedObject' );
)
);
}
} }
class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly { class DataExtensionTest_AppliedToDO extends DataExtension implements TestOnly {
public function testMethodApplied() { public function testMethodApplied() {
return "hello world"; return "hello world";
} }
} }
DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext1'); DataObject::add_extension('DataExtensionTest_MyObject', 'DataExtensionTest_Ext1');