Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » DataObjectManager - Translate

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: 868 Views
  • pouic
    Avatar
    Community Member
    16 Posts

    DataObjectManager - Translate Link to this post

    Hi,

    When I create a translated page and this page include one DataObject, the elements in dataObject created are not copied.

    Another question, adding images/files to data object...
    When popup open in first step need save and next step upload the file!!! Dont exist one single step to upload image?

    Class:

    static $has_many = array(
       'Itens' => 'WorkItens'
    );

    static $allowed_children = 'none';

    static $can_be_root = false;

    static $defaults = array (
       'ShowInMenus' => true,
       'ShowInSearch' => true
    );

    /**
    * @return CMSFields for CMS
    */
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $imgProjecto = new DataObjectManager(
    $this,
    'Itens',
    'WorkItens',
    array(
    'Thumb' => 'Photo',
    'Name' => 'Name'
    ),
    'getCMSFields_forPopup'
    );
    $imgProjecto->setAddTitle('images for this work');
    $imgProjecto->set_confirm_delete(true);
    $imgProjecto->setUseViewAll(true);
    $imgProjecto->setPageSize(20);

    $fields->addFieldToTab('Root.Content.WorkImages', $imgProjecto);

    return $fields;
    }

    DataObject:

    class WorkItens extends DataObject {
       
       static $db = array(
    'Name' => 'Varchar(255)'
       );
       
       static $defaults = array (
    'ShowInMenus' => false,
    'ShowInSearch' => false
       );
       
       static $has_one = array(
    'Work' => 'Work',
    'Photo' => 'Image'
       );

       public function getCMSFields_forPopup()
       {
          $img = new ImageField('Photo', 'Please Select an Image');
          $img -> folderName = 'work-images'; //THIS IS RELATIVE TO UPLOADS
          
          return new FieldSet(
    new TextField('Name', 'Image title'),
    $img
    );
       }
       
       public function getThumb(){
    if($this->PhotoID)
    return $this->Photo()->CMSThumbnail();
    else
    return '(No Photo)';
       }   
       
       public function showName(){
    return $this->Name;
       }

    }

    _config:

    MySQLDatabase::set_connection_charset('utf8');

    //definir timezone
    date_default_timezone_set('Europe/Lisbon');

    // Ativar o sortable no dataobject_manager
    SortableDataObject::add_sortable_class('WorkItens');
    Object::add_extension('DataObjectManager', 'Translatable');
    Object::add_extension('DataObjectManager_Item', 'Translatable');

    // Set the site locale
    i18n::set_locale('pt_PT');
    i18n::set_default_locale('pt_PT');
    i18n::$common_locales = array(
    'pt_PT' => array('Português', 'Portugal'),
    'en_US' => array('English', 'English'),
    'fr_FR' => array('Français', 'France')
    );

    Translatable::enable();
    Translatable::set_default_locale('pt_PT');

    // enable nested URLs for this site (e.g. page/sub-page/)
    SiteTree::enable_nested_urls();

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager - Translate Link to this post

    Use Uploadify. http://www.leftandmain.com/silverstripe-modules/2010/08/26/uploadify/

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

  • pouic
    Avatar
    Community Member
    16 Posts

    Re: DataObjectManager - Translate Link to this post

    Uploadify for upload image using one step only. Thanks i will try

    But for the translated? Any suggestions?

  • UncleCheese
    Avatar
    4085 Posts

    Re: DataObjectManager - Translate Link to this post

    There are all kinds of workarounds for getting Translatable to work with DataObjects. None of them are great, but it's worth looking into..

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

  • pouic
    Avatar
    Community Member
    16 Posts

    Re: DataObjectManager - Translate Link to this post

    UncleCheese show me one workaround exemple

  • pouic
    Avatar
    Community Member
    16 Posts

    Re: DataObjectManager - Translate Link to this post

    Any ideia?

  • wmk
    Avatar
    Community Member
    44 Posts

    Re: DataObjectManager - Translate Link to this post

    Hi Puic,

    do you also have to translate the dataobjects? Or are they just relations, images, files, stuff that doesn't have to be translated?

    If first, you'll have to add them to the translated page, too.

    If second, you can grab the original page and return the original dataobjecs, like:

    if ($this->Locale == 'de_DE') {
    $parent = $this->Parent();
    } else {
    $german = $this->getTranslation('de_DE');
    if ($german) {
    $parent = $german->Parent();
    }
    }
    if (!$parent) return;

    return $parent->Title;

    This example returns the title for the german parent (im my case, i always have a german page as original page per definition!)

    Hope that helps,

    Werner

  • pouic
    Avatar
    Community Member
    16 Posts

    Re: DataObjectManager - Translate Link to this post

    Hi Werner,

    i will try your code ;)

    tks

    868 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.