diff --git a/core/model/DataObject.php b/core/model/DataObject.php index 8723304af..913ac6fb7 100644 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -2543,6 +2543,7 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP } $labels = array_merge((array)$autoLabels, (array)$customLabels); + $this->extend('updateFieldLabels', $labels); return $labels; @@ -2832,33 +2833,6 @@ class DataObject extends ViewableData implements DataObjectInterface,i18nEntityP public function provideI18nEntities() { $entities = array(); - $db = eval("return {$this->class}::\$db;"); - if($db) foreach($db as $name => $type) { - $entities["{$this->class}.db_{$name}"] = array( - $name, - PR_MEDIUM, - 'Name of the object property, mainly used for automatically generating forms' - ); - } - - $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, - PR_MEDIUM, - 'Name of an object relation, mainly used for automatically generating forms' - ); - } - - $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, - PR_MEDIUM, - 'Name of an object relation, mainly used for automatically generating forms' - ); - } - $entities["{$this->class}.SINGULARNAME"] = array( $this->singular_name(), PR_MEDIUM, diff --git a/core/model/DataObjectDecorator.php b/core/model/DataObjectDecorator.php index 6fc34d5c8..a5c250b03 100755 --- a/core/model/DataObjectDecorator.php +++ b/core/model/DataObjectDecorator.php @@ -6,7 +6,7 @@ * @package sapphire * @subpackage model */ -abstract class DataObjectDecorator extends Extension implements i18nEntityProvider { +abstract class DataObjectDecorator extends Extension { /** * Statics on a {@link DataObject} subclass @@ -162,21 +162,6 @@ abstract class DataObjectDecorator extends Extension implements i18nEntityProvid if($field_labels) $lables = array_merge($lables, $field_labels); } } - - function provideI18nEntities() { - $entities = array(); - $fields = $this->extraStatics(); - $translatableAttributes = array('db','has_one','has_many','many_many'); - if($fields) foreach($fields as $att => $spec) { - if(!in_array($att, $translatableAttributes)) continue; - - if($spec) foreach($spec as $name => $type) { - $entities["{$this->class}.{$att}_{$name}"] = array($name); - } - } - - return $entities; - } } diff --git a/tests/i18n/i18nTest.php b/tests/i18n/i18nTest.php index 1f7f747d6..b7cab5668 100644 --- a/tests/i18n/i18nTest.php +++ b/tests/i18n/i18nTest.php @@ -16,36 +16,15 @@ class i18nTest extends SapphireTest { i18n::set_locale('de_DE'); $obj = new i18nTest_DataObject(); - $lang['en_US']['i18nTest_DataObject']['db_MyProperty'] = 'MyProperty'; - $lang['de_DE']['i18nTest_DataObject']['db_MyProperty'] = 'Mein Attribut'; + $lang['en_US']['i18nTest_DataObject']['MyProperty'] = 'MyProperty'; + $lang['de_DE']['i18nTest_DataObject']['MyProperty'] = 'Mein Attribut'; $this->assertEquals( $obj->fieldLabel('MyProperty'), 'Mein Attribut' ); - $lang['en_US']['i18nTest_DataObject']['has_one_HasOneRelation'] = 'HasOneRelation'; - $lang['de_DE']['i18nTest_DataObject']['has_one_HasOneRelation'] = 'Eins zu eins'; - $this->assertEquals( - $obj->fieldLabel('HasOneRelation'), - 'Eins zu eins' - ); - - $lang['en_US']['i18nTest_DataObject']['has_many_HasManyRelation'] = 'HasManyRelation'; - $lang['de_DE']['i18nTest_DataObject']['has_many_HasManyRelation'] = 'Viel zu eins'; - $this->assertEquals( - $obj->fieldLabel('HasManyRelation'), - 'Viel zu eins' - ); - - $lang['en_US']['i18nTest_DataObject']['many_many_ManyManyRelation'] = 'ManyManyRelation'; - $lang['de_DE']['i18nTest_DataObject']['many_many_ManyManyRelation'] = 'Viel zu viel'; - $this->assertEquals( - $obj->fieldLabel('ManyManyRelation'), - 'Viel zu viel' - ); - - $lang['en_US']['i18nTest_DataObject']['db_MyUntranslatedProperty'] = 'MyUntranslatedProperty'; + $lang['en_US']['i18nTest_DataObject']['MyUntranslatedProperty'] = 'MyUntranslatedProperty'; $this->assertEquals( $obj->fieldLabel('MyUntranslatedProperty'), 'My Untranslated Property' @@ -106,6 +85,13 @@ class i18nTest_DataObject extends DataObject implements TestOnly { 'ManyManyRelation' => 'Member' ); + function fieldLabels() { + $labels = parent::fieldLabels(); + $labels['MyProperty'] = _t('i18nTest_DataObject.MyProperty', 'My Property'); + + return $labels; + } + } class i18nTest_Object extends Object implements TestOnly, i18nEntityProvider { diff --git a/tests/i18n/i18nTextCollectorTest.php b/tests/i18n/i18nTextCollectorTest.php index d6a6e8cd6..44f377049 100644 --- a/tests/i18n/i18nTextCollectorTest.php +++ b/tests/i18n/i18nTextCollectorTest.php @@ -380,10 +380,6 @@ PHP; "\$lang['en_US']['i18nTestModule']['WITHNAMESPACE'] = 'Include Entity with Namespace';", $moduleLangFileContent ); - $this->assertContains( - "\$lang['en_US']['i18nTestModule']['db_MyField']", - $moduleLangFileContent - ); $this->assertContains( "\$lang['en_US']['i18nTestModuleInclude.ss']['NONAMESPACE'] = 'Include Entity without Namespace';", $moduleLangFileContent @@ -416,77 +412,13 @@ PHP; array( 'i18nTextCollectorTestMyObject.PLURALNAME', 'i18nTextCollectorTestMyObject.SINGULARNAME', - 'i18nTextCollectorTestMyObject.db_FirstProperty', - 'i18nTextCollectorTestMyObject.db_SecondProperty', - 'i18nTextCollectorTestMyObject.has_many_Relation', ) ); - $this->assertEquals( - 'FirstProperty', - $matches['i18nTextCollectorTestMyObject.db_FirstProperty'][0] - ); $this->assertEquals( 'My Object', $matches['i18nTextCollectorTestMyObject.SINGULARNAME'][0] ); } - - function testCollectFromEntityProvidersInCustomSubClass() { - $c = new i18nTextCollector(); - - $filePath = Director::baseFolder() . '/sapphire/tests/i18n/i18nTextCollectorTestMySubObject.php'; - $matches = $c->collectFromEntityProviders($filePath); - $this->assertEquals( - array_keys($matches), - array( - 'i18nTextCollectorTestMySubObject.PLURALNAME', - 'i18nTextCollectorTestMySubObject.SINGULARNAME', - 'i18nTextCollectorTestMySubObject.db_SubProperty', - 'i18nTextCollectorTestMySubObject.has_many_SubRelation', - ) - ); - $this->assertEquals( - 'SubProperty', - $matches['i18nTextCollectorTestMySubObject.db_SubProperty'][0] - ); - $this->assertEquals( - 'My Sub Object', - $matches['i18nTextCollectorTestMySubObject.SINGULARNAME'][0] - ); - } - - 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' - ); - $this->assertNotContains( - "\$lang['en_US']['i18nTestModuleDecorator']['has_one_Page'] = 'Page';", - $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' - ); - $this->assertContains( - "\$lang['en_US']['i18nTestModuleDecorator']['has_one_Page'] = 'Page';", - $otherModuleLangFileContent, - 'Decorated fields are stored in the module in which the decorator is placed' - ); - } } ?> \ No newline at end of file diff --git a/tests/i18n/i18nTextCollectorTestMySubObject.php b/tests/i18n/i18nTextCollectorTestMySubObject.php index 69b688ad5..7ec8ad151 100644 --- a/tests/i18n/i18nTextCollectorTestMySubObject.php +++ b/tests/i18n/i18nTextCollectorTestMySubObject.php @@ -15,6 +15,5 @@ class i18nTextCollectorTestMySubObject extends i18nTextCollectorTestMyObject imp static $singular_name = "My Sub Object"; static $plural_name = "My Sub Objects"; - } ?> \ No newline at end of file