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.

Customising the CMS /

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

TreeDropDownField in Popup (SS 2.3.2 / 2.3.3)


Go to End


8 Posts   3383 Views

Avatar
Andre

Community Member, 146 Posts

5 August 2009 at 7:03am

Hi there,
I was trying to write a Module for having a Menu with Shortlinks. Therefore my Idea was a class Shortlink, inheriting from DataObject and a ShortlinkPage having many shortlinks.
This is the Code:
class ShortLink extends DataObject{
static $db = array (
'LinkTitle' => 'Text'
);
static $has_one = array (
'ShortLink' => 'Page'
);
function getCMSFields_forPopup(){
$fields = new FieldSet();
$fields->push(new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:")));
$fields->push(new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page"));
return $fields;
}

}
class ShortLinkPage extends Page {

static $has_many = array (
'ShortLinks' => 'ShortLink'
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$shortLinks = new ComplexTableField(
$this,
_t("ShortLinkPage.SHORTLINKS", "Short Links:"),
'ShortLink',
null,
null
//"ShortLink.ShortLinkPageID = {$this->ID}"
);
$fields->addFieldToTab('Root.Content.Shortlinks', $shortLinks);
return $fields;
}
public function getShortLinks(){
$page = $this;
$Shortlinks = $this->ShortLinks();
print_r($Shortlinks); // this is still not ready, but isn't my problem at the moment
/*while(!$Menublock->ID && $page->ParentID != 0){
$page = $page->Parent();
if(!method_exists($page, 'LinkToMenublock') && $page->ParentID != 0){
$page = $page->Parent();
$Menublock = $page->LinkToMenublock();
}else{
$Menublock = $page->LinkToMenublock();
}
}
//return new DataObjectSet($Menublock->Children());
return $Menublock->Children();*/
}

}
class ShortLinkPage_Controller extends ExtendedPage_Controller {
}
What doesn't work is the TreeDropDownField inside the Popup for creating a new shortlink (in Version 2.3.2 and 2.3.3, didn't tested 2.3.1). Is this a general Problem, that doesn't work or have I been doing something wrong? Elsewhere is the an alternative way, to slect a page for a collection of Links?

Avatar
BurtOfOz

Community Member, 3 Posts

5 August 2009 at 9:34am

Gday Andre,

What do you mean by "doesn't work"? I ran up against some issues with the TreeDropdownField, but have things working ok now.

If you mean that it creates a single line box underneath the initial box, that makes it next to impossible to select a page from the tree, try changing the order of your fields in the FieldSet, such that the TreeDropdownField isn't the last one on the pop-up.

If it's something else, let me know and I'll see if I can help.

Avatar
Andre

Community Member, 146 Posts

5 August 2009 at 10:25pm

Now I'm a little confused. With "It doesn't work", I mean, the TreeDropdownField doesn't show up. Now I now I changed the order, which didn't help, and, what is more confusing, I commented the Textfield, but it still shows up (did /dev/build?flush=1 already a few times).

Here is My code again plus a Screenshot:

<?php

class ShortLink extends DataObject{
	static $has_one = array (
            'ShortLink' => 'Page'
      );

      static $db = array (
		'LinkTitle' => 'Text'
	);

	function getCMSFields_forPopup(){
		$fields = new FieldSet();
		$fields->push(new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page"));
            //$fields->push(new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:")));

		return $fields;
	}
	
}

?>

Attached Files
Avatar
Andre

Community Member, 146 Posts

6 August 2009 at 1:14am

Hi, me again,

the following is also not working. Now I get no fields inside the Popup.

<?php

class ShortLink extends DataObject{
	static $has_one = array (
            'ShortLink' => 'Page'
      );

      static $db = array (
		//'LinkTitle' => 'Text'
	);

	function getCMSFields_forPopup(){
		$fields = new FieldSet(
                  new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "Page")
                  //new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:"))
            );

		return $fields;
	}
	
}

?>

Do I have a stupid mistake, or is this a bug wtihin TreeDropdown or Popup?

Avatar
Andre

Community Member, 146 Posts

6 August 2009 at 11:41pm

Got it working now. Also changed Complextablefield to Dataobjectmanager.

<?php

class ShortLink extends DataObject{
      public static $has_one = array (
            'ShortLink' => 'SiteTree'
      );

      public static $db = array (
            'LinkTitle' => 'Text'
      );

      public function getCMSFields_forPopup(){
            $fields = new FieldSet(
                  new TreeDropdownField("ShortLink", _t("ShortLink.SHORTLINK", "Link Target:"), "SiteTree"),
                  new TextField('LinkTitle', _t("ShortLink.LINKTITLE", "Link Title:"))
            );

            return $fields;
      }     
}

?>

<?php

class ShortLinkPage extends ExtendedPage {
	
	static $has_many = array (
		'ShortLinks' => 'ShortLink'
	);

	public function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Shortlinks', new DataObjectManager(
                  $this,
                  _t("ShortLinkPage.SHORTLINKS", "Short Links:"),
                  'ShortLink',
                  array('LinkTitle' => _t("ShortLinkPage.LINKTITLE", "Link Title")),
                  'getCMSFields_forPopup'
            ));

		return $fields;
	}
}

class ShortLinkPage_Controller extends ExtendedPage_Controller {
}

?>

Avatar
Garrett

Community Member, 245 Posts

18 May 2011 at 8:21am

I am using SS 2.4.5 and am unable to get a TreeDropdownField to open in the popup modal window. Also, it completely breaks SimpleTinyMCEField.

//Garrett

Avatar
rodolfocartas

Community Member, 2 Posts

20 September 2011 at 5:39am

I'm facing the same problem. Did you fix it?

Avatar
Garrett

Community Member, 245 Posts

20 September 2011 at 7:18am

No, so I am using the SimpleTreeDropDownField object from DataObjectManager module. It's not as fancy but it works for my purposes.

//Garrett