Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Odd Translatable behavior

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1258 Views
  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Odd Translatable behavior Link to this post

    Hi Everyone,
    I have the following code in my _config file to make sitetree and dataobjects translatable:

    Object::add_extension('SiteTree', 'Translatable');
    Object::add_extension('DOStaffMember', 'Translatable'); //Dataobject

    Object::add_extension('DOEvent', 'Translatable'); //Dataobject
    Object::add_extension('DOAudioVideoFile', 'Translatable'); //Dataobject
    Object::add_extension('DOFolder', 'Translatable'); //Dataobject

    Object::add_extension('DOPatent', 'Translatable'); //Dataobject
    Object::add_extension('DOFrequentlyAskedQuestion', 'Translatable'); //Dataobject

    //Restrict all locales to this list:
    Translatable::set_allowed_locales(array(
          'en_US',
          'de_DE',
          'ja_JP'
       )
    );

    The problem that I am getting is that a 'Locale' column appears on my sitetree table (which is normal), but also on tables that have extended the Page class, like Homepage and Blog.

    this is messing up some things like Blog archive where it uses a Natural Join in a DB::query() call. (the join finds 2 locale tables and returns nothing)

    does anyone have any thoughts why these extra columns are being created? The site is using SS 2.3.3 or 2.3.4 (yes, i need to upgrade). I tried only decorating sitetree with Translatable, and removed the Decorators from the DataObjects, deleted the Locale tables from Homepage, but they are added once i do another dev/build/.

    I'd love to hear any suggestions.

    thanks,
    -Chris

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Odd Translatable behavior Link to this post

    I found out that a dataobjectdecorator that i am using on BlogEntry is causing the problem. something tells me that this is a bug between dataobjectdecorator and the Translatable extension. adding this decorator with this code causes the problems:

    // BlogEntryDecorator.php
    <?php

    class BlogEntryDecorator extends DataObjectDecorator {
       function extraStatics() {
          return array(
             'db' => array(
                'PodcastContent' => 'HTMLText',
             )
          );
       }
       public function updateCMSFields(FieldSet &$fields) {
          $fields->addFieldToTab('Root.Content.EmbedCode', new TextAreaField('PodcastContent', 'Embed Code'));
       }
    }
    ?>

    //mysite/_config.php
    <?php
    //...
    DataObject::add_extension('BlogEntry', 'BlogEntryDecorator');
    //...

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: Odd Translatable behavior Link to this post

    I've just tried your BlogEntryDecorator with the newest 2.3 and blog 0.2.1 - works as expected here, no duplicated Locale columns in the BlogEntry table. Sure you haven't added Translatable to BlogEntry at some point? Keep in mind that these columns won't be deleted automatically. Can you reproduce the problem on a fresh database?

  • ChrisBryer
    Avatar
    Community Member
    95 Posts

    Re: Odd Translatable behavior Link to this post

    Hi Ingo,
    Thanks for looking into this. i upgraded the site to 2.3.6 (was running 2.3.3) and deleted the locale columns from appropriate tables and everything works fine now. the reason why i hadnt upgraded the site to 2.3.6 was because i had to apply a patch #4199 to make CTF's work in all locales. i know that you want to avoid session variables in the solution, and i'm curious if you have a recommended solution to fix that problem. it just makes upgrading a little harder on a multi-lingual website.

    thanks again for looking into this! I really appreciate the help!
    -Chris

    1258 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.