Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

how to make dataobjects translatable (slideshow)


Go to End


1056 Views

Avatar
Sacher

Community Member, 1 Post

7 January 2017 at 8:57am

Hi all!

I am creating a multilingual page, the goal is to have the whole content available in three languages. I am using the translatable module, works fine for now.

Some pages contains a slideshow, meaning that I am associating a bunch of images and captions to these pages. Looks like this:

class Slide extends DataObject {

    private static $db = array(
        'Caption'     => 'Varchar(255)',
        'SortIndex'   => 'Int'
    );

    private static $has_one = array(
        'ParentPage' => 'Page',
        'Image' => 'Image'
    );
    
    public static $default_sort = 'SortIndex';
   
    public function getCMSFields() {
        // parent::getCMSFields() does all the hard work and creates the fields for Title, IsActive and Content.
        $fields = parent::getCMSFields();
        $fields->dataFieldByName('Caption')->setTitle('Titel');
        $fields->dataFieldByName('Image')->setTitle('Bild');
        $fields->dataFieldByName('Index')->setTitle('Reihenfolge');
        
        $fields->push(new TextField('Caption', 'Titel'));
        $fields->push(new UploadField('Image', 'Profile Image'));
        
        // Apply Translatable modifications
        $this->applyTranslatableFieldsUpdate($fields, 'updateCMSFields');

        return $fields;
    }
}

<?php

class SlideShowPage extends Page {

    private static $has_many = array(
        'Slides' => 'Slide'
    );

    public function getCMSFields() {
        $fields = parent::getCMSFields();

        $conf = GridFieldConfig_RelationEditor::create(10);
        $conf->addComponent(new GridFieldSortableRows('SortIndex'));

        $fields->addFieldToTab('Root.Slideshow', new GridField('Slide', 'Slides', $this->Slides(), $conf));
        
        // Apply Translatable modifications
        $this->applyTranslatableFieldsUpdate($fields, 'updateCMSFields');

        return $fields;
    }
}

I want to make these slideshows translatable as well. Meaning that I want to prepare the slide show once in the primary language, then hit the "create new translation" button, and get the slideshow available in the translated version as well, with the captions ready to be translated (similar as the main text content). According to the silverstripe-translatable docs this shall be possible. I have added these calls to applyTranslatableFieldsUpdate() (see in the code above) and added these lines to my _config.php file as well:

SlideShowPage::add_extension('Translatable');
Slide::add_extension('Translatable');

The table "Slide_translationgroups" is even created successfully and filled with new entries for each translation. But the content of table "Slide" is not copied.

What am I missing?

Thanks!
Sacher