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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Translatable + SiteTree + SimpleTreeDropdownField ?


Go to End


7 Posts   3904 Views

Avatar
patte

Community Member, 63 Posts

3 May 2010 at 7:57pm

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

Community Member, 63 Posts

13 May 2010 at 9:15pm

Has someone any idea?

Avatar
craesh

Community Member, 25 Posts

26 November 2010 at 4:42am

Hi patte,

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

Avatar
craesh

Community Member, 25 Posts

26 November 2010 at 5:05am

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

Community Member, 25 Posts

26 November 2010 at 5:48am

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

Community Member, 271 Posts

11 February 2011 at 8:27am

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

Avatar
Nobrainer Web

Community Member, 138 Posts

11 July 2012 at 5:30am

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?