mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX Collecting i18n entities for decorators separately from the decorated classes, as decorated properties like $db have to be stored in the module of the decorated, not in the module of the decorated class.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65057 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
fd7bc64107
commit
d102a902b9
@ -12,6 +12,7 @@
|
||||
*
|
||||
* @package sapphire
|
||||
* @subpackage i18n
|
||||
* @uses i18nTextCollector->collectFromEntityProviders()
|
||||
*/
|
||||
interface i18nEntityProvider {
|
||||
|
||||
|
@ -188,6 +188,9 @@ class i18nTextCollector extends Object {
|
||||
return $entitiesArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @uses i18nEntityProvider
|
||||
*/
|
||||
function collectFromEntityProviders($filePath) {
|
||||
$entitiesArr = array();
|
||||
|
||||
|
@ -2843,7 +2843,7 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
||||
public function provideI18nEntities() {
|
||||
$entities = array();
|
||||
|
||||
$db = $this->uninherited('db', true);
|
||||
$db = eval("return {$this->class}::\$db;");
|
||||
if($db) foreach($db as $name => $type) {
|
||||
$entities["{$this->class}.db_{$name}"] = array(
|
||||
$name,
|
||||
@ -2852,7 +2852,7 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
||||
);
|
||||
}
|
||||
|
||||
$has_many = $this->uninherited('has_many', true);
|
||||
$has_many = eval("return {$this->class}::\$has_many;");
|
||||
if($has_many) foreach($has_many as $name => $class) {
|
||||
$entities["{$this->class}.has_many_{$name}"] = array(
|
||||
$name,
|
||||
@ -2861,7 +2861,7 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP
|
||||
);
|
||||
}
|
||||
|
||||
$many_many = $this->uninherited('many_many', true);
|
||||
$many_many = eval("return {$this->class}::\$many_many;");
|
||||
if($many_many) foreach($many_many as $name => $class) {
|
||||
$entities["{$this->class}.many_many_{$name}"] = array(
|
||||
$name,
|
||||
|
@ -6,7 +6,7 @@
|
||||
* @package sapphire
|
||||
* @subpackage model
|
||||
*/
|
||||
abstract class DataObjectDecorator extends Extension {
|
||||
abstract class DataObjectDecorator extends Extension implements i18nEntityProvider {
|
||||
|
||||
/**
|
||||
* Statics on a {@link DataObject} subclass
|
||||
@ -151,6 +151,21 @@ abstract class DataObjectDecorator extends Extension {
|
||||
}
|
||||
}
|
||||
|
||||
function provideI18nEntities() {
|
||||
$entities = array();
|
||||
$fields = $this->extraDBFields();
|
||||
$translatableAttributes = array('db','has_one','has_many','many_many');
|
||||
foreach($fields as $att => $spec) {
|
||||
if(!in_array($att, $translatableAttributes)) continue;
|
||||
|
||||
foreach($spec as $name => $type) {
|
||||
$entities["{$this->class}.{$att}_{$name}"] = array($name);
|
||||
}
|
||||
}
|
||||
|
||||
return $entities;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
Object::extend('i18nTestModule', 'i18nTestModuleDecorator');
|
||||
?>
|
@ -1,12 +1,10 @@
|
||||
<?php
|
||||
class i18nOtherModule extends Object {
|
||||
function __construct() {
|
||||
function mymethod() {
|
||||
_t(
|
||||
'i18nOtherModule.ENTITY',
|
||||
'Other Module Entity',
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
}
|
||||
?>
|
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
class i18nTestModuleDecorator extends DataObjectDecorator {
|
||||
function extraDBFields() {
|
||||
return array(
|
||||
'db' => array(
|
||||
'MyExtraField' => 'Varchar'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
@ -1,5 +1,10 @@
|
||||
<?php
|
||||
class i18nTestModule extends Object {
|
||||
class i18nTestModule extends DataObject implements TestOnly {
|
||||
|
||||
static $db = array(
|
||||
'MyField' => 'Varchar',
|
||||
);
|
||||
|
||||
function myMethod() {
|
||||
_t(
|
||||
'i18nTestModule.ENTITY',
|
||||
|
@ -29,10 +29,12 @@ class i18nTextCollectorTest extends SapphireTest {
|
||||
global $_CLASS_MANIFEST;
|
||||
$_CLASS_MANIFEST['i18nTestModule'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php';
|
||||
$_CLASS_MANIFEST['i18nTestModule_Addition'] = $this->alternateBasePath . '/i18ntestmodule/code/i18nTestModule.php';
|
||||
$_CLASS_MANIFEST['i18nTestModuleDecorator'] = $this->alternateBasePath . '/i18nothermodule/code/i18nTestModuleDecorator.php';
|
||||
|
||||
global $_ALL_CLASSES;
|
||||
$_ALL_CLASSES['parents']['i18nTestModule'] = array('Object'=>'Object');
|
||||
$_ALL_CLASSES['parents']['i18nTestModule'] = array('DataObject'=>'DataObject','Object'=>'Object');
|
||||
$_ALL_CLASSES['parents']['i18nTestModule_Addition'] = array('Object'=>'Object');
|
||||
$_ALL_CLASSES['parents']['i18nTestModuleDecorator'] = array('DataObjectDecorator'=>'DataObjectDecorator','Object'=>'Object');
|
||||
|
||||
global $_TEMPLATE_MANIFEST;
|
||||
$_TEMPLATE_MANIFEST['i18nTestModule.ss'] = array(
|
||||
@ -453,5 +455,28 @@ PHP;
|
||||
);
|
||||
}
|
||||
|
||||
function testCollectDecoratedFields() {
|
||||
$c = new i18nTextCollector();
|
||||
$c->basePath = $this->alternateBasePath;
|
||||
$c->baseSavePath = $this->alternateBaseSavePath;
|
||||
$c->run();
|
||||
|
||||
$moduleLangFile = "{$this->alternateBaseSavePath}/i18ntestmodule/lang/" . $c->getDefaultLocale() . '.php';
|
||||
$moduleLangFileContent = file_get_contents($moduleLangFile);
|
||||
$this->assertNotContains(
|
||||
"\$lang['en_US']['i18nTestModuleDecorator']['db_MyExtraField'] = 'MyExtraField';",
|
||||
$moduleLangFileContent,
|
||||
'Decorated fields are not stored in the module of the decorated file if the decorator is located in another module'
|
||||
);
|
||||
|
||||
$otherModuleLangFile = "{$this->alternateBaseSavePath}/i18nothermodule/lang/" . $c->getDefaultLocale() . '.php';
|
||||
$otherModuleLangFileContent = file_get_contents($otherModuleLangFile);
|
||||
$this->assertContains(
|
||||
"\$lang['en_US']['i18nTestModuleDecorator']['db_MyExtraField'] = 'MyExtraField';",
|
||||
$otherModuleLangFileContent,
|
||||
'Decorated fields are stored in the module in which the decorator is placed'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user