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
@ -63,9 +63,9 @@ abstract class DataExtension extends Extension {
|
|||||||
if(Object::has_extension(get_parent_class($class), $extensionClass)) return;
|
if(Object::has_extension(get_parent_class($class), $extensionClass)) return;
|
||||||
|
|
||||||
// If there aren't any extraStatics we shouldn't try to load them.
|
// If there aren't any extraStatics we shouldn't try to load them.
|
||||||
if ( ! method_exists($extensionClass, $extraStaticsMethod) ) return;
|
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) {
|
if($statics) {
|
||||||
foreach($statics as $name => $newVal) {
|
foreach($statics as $name => $newVal) {
|
||||||
@ -153,11 +153,14 @@ abstract class DataExtension extends Extension {
|
|||||||
*
|
*
|
||||||
* Return a map where the keys are db, has_one, etc, and the values are
|
* Return a map where the keys are db, has_one, etc, and the values are
|
||||||
* additional fields/relations to be defined.
|
* 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
|
* @return array Returns a map where the keys are db, has_one, etc, and
|
||||||
* the values are additional fields/relations to be defined.
|
* the values are additional fields/relations to be defined.
|
||||||
*/
|
*/
|
||||||
function extraStatics() {
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,13 @@ class Hierarchy extends DataExtension {
|
|||||||
function augmentWrite(&$manipulation) {
|
function augmentWrite(&$manipulation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function extraStatics($class = null) {
|
/**
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
* @param string $extension
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'has_one' => array(
|
'has_one' => array(
|
||||||
// TODO this method is called *both* statically and on an instance
|
// TODO this method is called *both* statically and on an instance
|
||||||
|
@ -95,13 +95,20 @@ class Versioned extends DataExtension {
|
|||||||
$this->liveStage = array_pop($stages);
|
$this->liveStage = array_pop($stages);
|
||||||
}
|
}
|
||||||
|
|
||||||
function extraStatics($class) {
|
/**
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
* @param string $extension
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
'Version' => 'Int',
|
'Version' => 'Int',
|
||||||
),
|
),
|
||||||
'has_many' => array(
|
'has_many' => array(
|
||||||
'Versions' => $class,
|
// TODO this method is called *both* statically and on an instance
|
||||||
|
'Versions' => ($class) ? $class : $this->owner->class,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,13 @@ class FulltextSearchable extends DataExtension {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
function extraStatics($class = null, $extension = null) {
|
/**
|
||||||
|
*
|
||||||
|
* @param string $class
|
||||||
|
* @param string $extension
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function extraStatics($class=null, $extension=null) {
|
||||||
if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) {
|
if($extension && preg_match('/\([\'"](.*)[\'"]\)/', $extension, $matches)) {
|
||||||
$searchFields = $matches[1];
|
$searchFields = $matches[1];
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
class i18nTestModuleExtension extends DataExtension {
|
class i18nTestModuleExtension extends DataExtension {
|
||||||
function extraStatics() {
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
'MyExtraField' => 'Varchar'
|
'MyExtraField' => 'Varchar'
|
||||||
|
@ -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) {
|
function extraStatics($class=null, $extension=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') {
|
||||||
@ -198,7 +198,7 @@ class DataExtensionTest_PlayerExtension extends DataExtension implements TestOnl
|
|||||||
|
|
||||||
class DataExtensionTest_ContactRole extends DataExtension implements TestOnly {
|
class DataExtensionTest_ContactRole extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
function extraStatics() {
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
'Website' => 'Varchar',
|
'Website' => 'Varchar',
|
||||||
@ -293,7 +293,7 @@ class DataExtensionTest_Ext2 extends DataExtension implements TestOnly {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DataExtensionTest_Faves extends DataExtension implements TestOnly {
|
class DataExtensionTest_Faves extends DataExtension implements TestOnly {
|
||||||
public function extraStatics() {
|
public function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'many_many' => array(
|
'many_many' => array(
|
||||||
'Faves' => 'DataExtensionTest_RelatedObject'
|
'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 {
|
class DataObjectTest_Team_Extension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
function extraStatics() {
|
function extraStatics($class=null, $extension=null) {
|
||||||
return array(
|
return array(
|
||||||
'db' => array(
|
'db' => array(
|
||||||
'ExtendedDatabaseField' => 'Varchar'
|
'ExtendedDatabaseField' => 'Varchar'
|
||||||
|
Loading…
Reference in New Issue
Block a user