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.

Data Model Questions /

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

Problem creating TreeMultiselectField to look up Page


Go to End


14 Posts   7889 Views

Avatar
Aaron Brockhurst

Community Member, 30 Posts

27 March 2009 at 11:36am

Edited: 27/03/2009 11:37am

Hi Mo

This is exactly what i am want to achieve and this all works fine for the first page I edit and select the check boxes for. However it's not updating the database table with any other page edits.

It looks like it's saving the changes made on the first edit of the first page and then not saving any other changes to any other pages

I get exactly the same results with the code you put.

Which version of SilverStripe are you using? I'm doing this on 2.3

Thanks

Aaron

Avatar
Aaron Brockhurst

Community Member, 30 Posts

28 March 2009 at 1:13pm

Hooray, I found a solution. It's not the most user friendly if you have lots of content

I changed the TreeMultiselectField to CheckboxSetField using the following:

function getCMSFields() {
$fields = parent::getCMSFields();
$pageList = DataObject::get('SlimJimsContentPage');
$fields->addFieldToTab("Root.Content.LinkedPages",new CheckboxSetField('SlimjimsLinkedPages','Select all related pages to appear in the right column', $pageList));
return $fields;
}

And this seems to be updating the database OK. Am still not sure why the TreeMultiselectField wasn't updating the database table for more than one page. If I find an answer I'll update

Aaron

Avatar
Nobrainer Web

Community Member, 138 Posts

12 January 2010 at 11:25am

Hi,

I have the exact same problem as Aaron - i have used the code from Mo's post.
I can select and save the checked pages for one page.
When i go to another page, i do get the dropdown, everything seems to be saved, but it is not, so when i reload the CMS the field of the new page is blank.

In Page.php i have:

class Page extends SiteTree {
	
	...
	
	public static $many_many = array(
		'BotLinksList'   => 'Page'
	);
	
	public function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$fields->addFieldToTab('Root.Content.Main', new TextField( 'TitleDescription', "Page Description"));
		$fields->addFieldToTab('Root.Content.Links', new TreeMultiselectField( 'BotLinksList', 'Bottom links', 'SiteTree' ));
		return $fields;
	}
...

My db now has a Page_BotLinksList table, with the fields ID, PageID, SiteTreeID, ChildID

Any help is appriciated, thx.

Avatar
Juanitou

Community Member, 323 Posts

8 March 2010 at 6:37am

Edited: 08/03/2010 6:40am

It seems there is a bug somewhere in TreeMultiselectField, isn’t it? Has somebody submitted a ticket to Trac? If there’s no bug (and I think it’s probably us that are not understanding how it works), maybe a developer will explain how to use it! ;-)

Avatar
mattclegg

Community Member, 56 Posts

16 August 2010 at 12:23am

I'm not sure if this is a bug or not but I'v found that the $many_many 'key' should be the same as the 'class' for a TreeMultiselectField or ManyManyComplexTableField within a Page::getCMSFields().

For example, this works;

class ClientType extends Page {
	static $many_many = array( 
		'ServiceTree' => 'ServiceTree'
	);
	function getCMSFields() {
    	    	$fields = parent::getCMSFields();
    	    	$fields->addFieldToTab("Root.Content.Main", new TreeMultiselectField("ServiceTree", "Related Services", "ServiceTree"));
/**
OR;
    	$rcTablefield = new ManyManyComplexTableField( 
         $this->owner, 
         'ServiceTree', 
         'ServiceTree',
         array( 
            'Title' => 'ArticleTitle' 
         ));  
      $rcTablefield->setPermissions(array('show'));
      $rcTablefield->setPageSize('150');  
      $fields->addFieldToTab('Root.Content.RelatedContent', $rcTablefield ); 
**/   
    	}
}
class ServiceTree extends Page{
// A class similar BlogTree which gets extended

	static $many_many = array(
      		'ClientTypePages' => 'ClientType'
	);
}

But it appears to work differently when customising the SiteConfig ie;

class CustomSiteConfig extends DataObjectDecorator {
	function extraStatics() {
		return array(
			'many_many' => array(
				'FooterLinks' => 'SiteTree'
        	);
	}
	public function updateCMSFields(FieldSet &$fields) {
		$fields->addFieldToTab("Root.Main", new CompositeField(
			new TreeMultiselectField("FooterLinks", "Footer Links", "SiteTree")
		));
}

And I think DOM requires that the 'key' be different to the 'class' ?

Avatar
Bureau Berg

Community Member, 7 Posts

6 March 2012 at 3:05am

@All, Thanks for sharing.

@Aaron, Did you got any solution to make this work with TreeMultiselectField custom page list?

my code is working great with "CheckboxSetField". But not working with TreeMultiselectField in case of custom page list "NewsPage".

My working Code with "CheckboxSetField":
------------------------------------------------------------
public static $many_many = array(
"FeaturedArticle"=>"NewsPage",
);

public function getCMSFields() {

$fields = parent::getCMSFields();
$pageList = DataObject::get('NewsPage');

$f = parent::getCMSFields();
$f->addFieldsToTab("Root.Content.FeaturedArticle", array(
new CheckboxSetField("FeaturedArticle", "Choose a your featured article:", $pageList),
));

return $f;
}
------------------------------------------------------------

Though when I use "TreeMultiselectField " this with "SiteTree" it works.

working Code with SiteTree is :

public static $many_many = array(
"FeaturedArticle"=>"SiteTree",
);

public function getCMSFields() {

$f = parent::getCMSFields();
$f->addFieldsToTab("Root.Content.FeaturedArticle", array(
new TreeMultiSelectField("FeaturedArticle", "Choose a your featured article:", "SiteTree"),
));

}

Any idea why it is not working with "NewsPage" class in TreeMultiselectField ?

Go to Top