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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DataObjectManager - Translate


Reply


8 Posts   980 Views

Avatar
pouic

Community Member, 19 Posts

4 August 2011 at 12:06pm

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();

Avatar
UncleCheese

Forum Moderator, 4096 Posts

5 August 2011 at 3:35am

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

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

Avatar
pouic

Community Member, 19 Posts

5 August 2011 at 10:07pm

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

But for the translated? Any suggestions?

Avatar
UncleCheese

Forum Moderator, 4096 Posts

5 August 2011 at 11:25pm

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

Avatar
pouic

Community Member, 19 Posts

26 August 2011 at 7:26am

UncleCheese show me one workaround exemple :)

Avatar
pouic

Community Member, 19 Posts

31 August 2011 at 10:33am

Any ideia?

Avatar
wmk

Community Member, 46 Posts

8 September 2011 at 1:07am

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

Avatar
pouic

Community Member, 19 Posts

8 September 2011 at 1:13am

Hi Werner,

i will try your code ;)

tks