mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX Versioned returns error on singleton($className)->summaryFields()
This solves a bugfix when calling singleton($className)->summaryFields() and Versioned kicks back. It is needed to by the GridField functionality to get default columns to show. This is due to DataExtension calls ClassName::extraStatics() when calling ::load_extra_statics() statically, we need to pass in class and extension.
This commit is contained in:
parent
f815425b4d
commit
260a9e230c
@ -65,7 +65,7 @@ abstract class DataExtension extends Extension {
|
||||
// If there aren't any extraStatics we shouldn't try to load them.
|
||||
if (!method_exists($extensionClass, $extraStaticsMethod) ) return;
|
||||
|
||||
$statics = call_user_func(array($extensionClass, $extraStaticsMethod), $class, $extension);
|
||||
$statics = call_user_func(array(singleton($extensionClass), $extraStaticsMethod), $class, $extension);
|
||||
|
||||
if($statics) {
|
||||
foreach($statics as $name => $newVal) {
|
||||
@ -154,10 +154,13 @@ abstract class DataExtension extends Extension {
|
||||
* Return a map where the keys are db, has_one, etc, and the values are
|
||||
* additional fields/relations to be defined.
|
||||
*
|
||||
* @param $class since this method might be called on the class directly
|
||||
* @param $extension since this can help to extract parameters to help set indexes
|
||||
*
|
||||
* @return array Returns a map where the keys are db, has_one, etc, and
|
||||
* the values are additional fields/relations to be defined.
|
||||
*/
|
||||
function extraStatics() {
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array();
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,13 @@ class Hierarchy extends DataExtension {
|
||||
function augmentWrite(&$manipulation) {
|
||||
}
|
||||
|
||||
function extraStatics($class = null) {
|
||||
/**
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $extension
|
||||
* @return array
|
||||
*/
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'has_one' => array(
|
||||
// TODO this method is called *both* statically and on an instance
|
||||
|
@ -95,13 +95,20 @@ class Versioned extends DataExtension {
|
||||
$this->liveStage = array_pop($stages);
|
||||
}
|
||||
|
||||
function extraStatics($class) {
|
||||
/**
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $extension
|
||||
* @return array
|
||||
*/
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'db' => array(
|
||||
'Version' => 'Int',
|
||||
),
|
||||
'has_many' => array(
|
||||
'Versions' => $class,
|
||||
// TODO this method is called *both* statically and on an instance
|
||||
'Versions' => ($class) ? $class : $this->owner->class,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
@ -74,6 +74,12 @@ class FulltextSearchable extends DataExtension {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $class
|
||||
* @param string $extension
|
||||
* @return array
|
||||
*/
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) {
|
||||
$searchFields = $matches[1];
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
class i18nTestModuleExtension extends DataExtension {
|
||||
function extraStatics() {
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'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) {
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
// Only add these extensions if the $class is set to DataExtensionTest_Player, to
|
||||
// test that the argument works.
|
||||
if($class == 'DataExtensionTest_Player') {
|
||||
@ -198,7 +198,7 @@ class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnl
|
||||
|
||||
class DataExtensionTest_ContactRole extends DataExtension implements TestOnly {
|
||||
|
||||
function extraStatics() {
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'db' => array(
|
||||
'Website' => 'Varchar',
|
||||
@ -293,7 +293,7 @@ class DataExtensionTest_Ext2 extends DataExtension implements TestOnly {
|
||||
}
|
||||
|
||||
class DataExtensionTest_Faves extends DataExtension implements TestOnly {
|
||||
public function extraStatics() {
|
||||
public function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'many_many' => array(
|
||||
'Faves' => 'DataExtensionTest_RelatedObject'
|
||||
|
2
tests/model/DataObjectTest.php
Executable file → Normal file
2
tests/model/DataObjectTest.php
Executable file → Normal file
@ -1172,7 +1172,7 @@ class DataObjectTest_FieldlessSubTable extends DataObjectTest_Team implements Te
|
||||
|
||||
class DataObjectTest_Team_Extension extends DataExtension implements TestOnly {
|
||||
|
||||
function extraStatics() {
|
||||
function extraStatics($class=null, $extension=null) {
|
||||
return array(
|
||||
'db' => array(
|
||||
'ExtendedDatabaseField' => 'Varchar'
|
||||
|
Loading…
Reference in New Issue
Block a user