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

Translatable + SiteTree + SimpleTreeDropdownField ?


Reply

7 Posts   2217 Views

Avatar
patte

3 May 2010 at 7:57pm Community Member, 63 Posts

Hi,

I am using the latest DOM with SS 2.4rc2 - everything seems to work perfect ;-)

But I am not getting one last thing up and running with my multilingual site - the SimpleTreeDropdownField is just showing its tree from the default site and not the translated tree If I am withinin another language.

How can I configure SimpleTreeDropdownField to select only the tree items from the current language?

   static $has_one = array (
      'Page' => 'Page',
      'Bild' => 'Image',
      'MyUrl' => 'SiteTree',
   );
   
   
   
   public function getCMSFields_forPopup()
   {
   $f = new FieldSet(
      $dropdown = new SimpleTreeDropdownField("MyUrlID", "Bitte waehlen Sie das Ziel aus", "SiteTree"),
      new TextField('Ueberschrift'),
      new SimpleWysiwygField('Beschreibung'),
      new ImageField('Bild')
      );
   $dropdown->setEmptyString('-- Please select --');
   return $f;
   }

Can someone please give me a tip for that?

Thanks much
patte

Avatar
patte

13 May 2010 at 9:15pm Community Member, 63 Posts

Has someone any idea?

Avatar
craesh

26 November 2010 at 4:42am Community Member, 25 Posts

Hi patte,

have you solved it? I'm facing the same problem.

Avatar
craesh

26 November 2010 at 5:05am Community Member, 25 Posts

I just solved it by myself. This is what I did:

<?php
class MyDO extends DataObject {

   public static $db = array(
      //...
   );

   public static $has_one = array(
      'Page' => 'Page',
      'Link' => 'SiteTree',
   );

   public function getCMSFields_forPopup() {
      $homeID = 1;
      if ( $this->Page()->hasExtension('Translatable') )
         $homeID = $this->Page()->PageForCurrentLocale('home')->ID;
      
      return new FieldSet(
         //...
         new SimpleTreeDropdownField( 'LinkID', 'Link', $sourceClass = "SiteTree", $value = "", $labelField = "Title", $form = null, $emptyString = null, $parentID = $homeID )
      );
   }

}
?>

PageForCurrentLocale is a method I defined in Page:

   public function PageForCurrentLocale( $pagename ) {
      if ( Object::has_extension('Page','Translatable') ) {
         Translatable::disable_locale_filter();
         $page = DataObject::get_one("Page","URLSegment='$pagename'");
         Translatable::enable_locale_filter();
         if ( empty($page) )
            return;
         else if ( Translatable::get_current_locale() != Translatable::default_locale() )
            return $page->getTranslation( Translatable::get_current_locale() );
         else
            return $page;
      } else {
         return DataObject::get_one("Page","URLSegment='$pagename'");
      }
   }

Greetings!
craesh

Avatar
craesh

26 November 2010 at 5:48am Community Member, 25 Posts

I'm sorry, but the above code won't work as expected. There does not seam to be an easy way, but you can get all pages ignoring the current locale this way:

   public function getCMSFields_forPopup() {
      if ( Object::has_extension('Page','Translatable') )
         Translatable::disable_locale_filter();
      $fields = new FieldSet(
         //...
         new SimpleTreeDropdownField( 'LinkID', 'Link' )
      );
      if ( Object::has_extension('Page','Translatable') )
         Translatable::enable_locale_filter();
      return $fields;
   }

Avatar
Martijn

11 February 2011 at 8:27am Community Member, 271 Posts

I fixed this by adding Translatable::set_current_locale($this->Locale); in Page::getCMSFields();

Avatar
Nobrainer Web

11 July 2012 at 5:30am Community Member, 135 Posts

Martijn you write that fixed this by adding Translatable::set_current_locale($this->Locale); in Page::getCMSFields();
but i'm not able to make this work.

I should add that i'm working with dataobject managed via the ModelAdmin.

I'm simply not having any luck making the TreeDropdownField display anything but the default language.

Anyone have any info on how to do this?