Jump to:

7939 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Translatable Data Objects

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 893 Views
  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Translatable Data Objects Link to this post

    Hi.

    I like to make data objects translatable just the same way, pages are translatable through the site-tree.

    When I hit "Translate", the pages are put into the specified language site-tree, but attached objects e.g. images are not copied.

    Below you find my approach so far. I'm using SS 2.4.3

    Couldn't find a solution in the forums, yet. Perhaps you can help?

    _config.php:
    Object::add_extension('HeaderImage', 'Translatable');

    CategoryPage:
    class CategoryPage extends Page {

    static $has_many = array(
    'HeaderImages' => 'HeaderImage',
    );

    function getCMSFields() {

    $fields = parent::getCMSFields();

        $manager = new DataObjectManager(
    $this,
    'HeaderImages', // relation name
    'HeaderImage', // object class
    HeaderImage::$field_names, // fields to show in table
    HeaderImage::getCMSFields_forPopup(), // form that pops up for edit
    "CategoryPageID = {$this->ID}" // a filter to only display item associated with this page
    );

    $manager->setAddTitle('Header');
    $manager->setSingleTitle('Header Image');
    $manager->setPluralTitle('Header Images');
    $manager->setPopupWidth(400);
    $manager->setPerPageMap(array(20,40,80));

        $fields->addFieldToTab('Root.Content.Header', $manager);
       }
    }

    HeaderImage.php:
    class HeaderImage extends DataObject {

    static $has_one = array(
    'Image' => 'Image',
    'Category' => 'Category',
    'RootFolder' => 'Folder'
    );

    static $field_names = array(
    'Thumbnail' => 'Image',
    'Title' => 'Title',
    );

    function getCMSFields_forPopup() {

    $fields = new FieldSet();

        $picfolderName = $this->RootFolder()->FileName;
        $picfolderName = str_replace('assets/','',$picfolderName);
       
        $fields->push(new TextField('Title', 'Title'));
        $fields->push(new TextField('Subtitle', 'Subtitle'));
        $fields->push(new TextField('Text', 'Text'));
        $fields->push(new DropdownField('Alignment','Alignment',singleton('HeaderImage')->dbObject('Alignment')->enumValues()));
        $fields->push(new TextField('Link', 'Link'));
    $fields->push(new ImageField('Image', 'Image', null, null, null, $picfolderName));

    return $fields;
    }

       function getThumbnail()
       {
        if ($Image = $this->Image())
        {
        return $Image->CMSThumbnail();
        }
        else
        {
        return '(No Image)';
        }
       }

       public function onBeforeWrite() {
          parent::onBeforeWrite();
          $this->Locale = Translatable::get_current_locale();
       }

    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: Translatable Data Objects Link to this post

    My understanding is that Translatable is an extension for SiteTree objects only.

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Translatable Data Objects Link to this post

    Thank you, UncleCheese.

    That exactly was my fear. Do you know any alternatives?

  • UncleCheese
    Avatar
    4085 Posts

    Re: Translatable Data Objects Link to this post

    How many languages? How many fields are you translating on the object?

  • SamSmooth
    Avatar
    Community Member
    18 Posts

    Re: Translatable Data Objects Link to this post

    At the beginning the will be perhaps 10 languages,
    and not more than 10 translations per object. E.g. For an Image Gallery

    If possible both should be kept flexible for the admin.

  • UncleCheese
    Avatar
    4085 Posts

    Re: Translatable Data Objects Link to this post

    OK, never mind, then.

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts
    893 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.