Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Translatable + SiteTree + SimpleTreeDropdownField ?

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: 2188 Views
  • patte
    Avatar
    Community Member
    63 Posts

    Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    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

  • patte
    Avatar
    Community Member
    63 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    Has someone any idea?

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    Hi patte,

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

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    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

  • craesh
    Avatar
    Community Member
    25 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    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;
       }

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

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

  • Nobrainer Web
    Avatar
    Community Member
    134 Posts

    Re: Translatable + SiteTree + SimpleTreeDropdownField ? Link to this post

    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?

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