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

SimpleStreeDropdownBroken after last update


Go to End


10 Posts   2047 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

10 September 2010 at 11:09pm

Hi UC,

After the last update to SimpleTreeDropdownField, it no longer owrks, just producing an empty dropdown.

I tracked it down to the if() statement that was added inside the foreach:

//DOES NOT WORK
if($child->ClassName == $this->sourceClass) {
	$text = $child->__get($this->labelField);
	$options[$child->ID] = empty($text) ? "<em>$indent Untitled</em>" : $indent.$text;
}

//WORKS
$text = $child->__get($this->labelField);
$options[$child->ID] = empty($text) ? "<em>$indent Untitled</em>" : $indent.$text;


Not quite sure why you would want to be doing that, surely that would mean it only showed children that were the same class as the parent?

Aram

--------------------------------------------------------------

www.SSbits.com - SilverStripe Tutorials, Tips and other bits

Avatar
UncleCheese

Forum Moderator, 4102 Posts

11 September 2010 at 2:10am

Aram, could you give me the context for that breaking? That was a necessary patch, because if you are using a class other than "SiteTree", let's say "NewsArticle", the getHierarchy() method never gets past the first level, if all your NewsArticle pages are on the second level. So rather than fetching $this->sourceClass, it fetches "SiteTree", and then checks if the class matches before adding it into the map.

... at least, that's what it SHOULD be doing. Can I see the code you're using?

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Carbon Crayon

Community Member, 598 Posts

11 September 2010 at 3:30am

Edited: 11/09/2010 3:31am

Hi UC,

here is the code:

<?php

class HomePageStory extends DataObject {

	static $db = array
	(
		'Title' => 'Varchar(255)',
		'Text' => 'Text'
	);
	
	static $has_one = array
	(
		'HomePage' => 'HomePage',
		'LinkedPage' => 'SiteTree'
	);
	
	static $summary_fields = array
	(
		'Title' => 'Title',
		'Text' => 'Text',
		'LinkedPage.Title' => 'Link title',
	);
	
	public function getCMSFields()
	{
		$fields = new FieldSet();
		
		$fields->push(new TextField('Title'));
		$fields->push(new TextareaField('Text'));
		$fields->push(new SimpleTreeDropdownField('LinkedPageID', 'Linked page', 'SiteTree'));

		return $fields;
	}
	
}

Cheers

Aram

Avatar
Carbon Crayon

Community Member, 598 Posts

14 September 2010 at 3:43am

Still having the same problem....

Is nobody else experiencing this?

Cheers

Aram

Avatar
UncleCheese

Forum Moderator, 4102 Posts

14 September 2010 at 6:49am

Just checked in the patch, Aram. Thanks for your patience!

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
Carbon Crayon

Community Member, 598 Posts

14 September 2010 at 8:22am

Awesome, thanks!

Avatar
dhensby

Community Member, 253 Posts

16 September 2010 at 1:58am

r495 caused some issues on one of my sites because the new SimpleTreeDropdown now has a new parameter in the construct that has just been added in the middle of the others.

It would be nice for API changes like this to add the new params at the end of the list to allow for backward compatibility. Also, the construct doesn't make sure that the number passed for the parent id is an integer.

Alternatively, you could branch your SVN repo so that major API changes like this are on a separate branch.

This should fix it:

Index: dataobject_manager/code/dropdown_fields/SimpleTreeDropdownField.php
===================================================================
--- dataobject_manager/code/dropdown_fields/SimpleTreeDropdownField.php (revision 495)
+++ dataobject_manager/code/dropdown_fields/SimpleTreeDropdownField.php (working copy)
@@ -9,7 +9,7 @@
{
$this->sourceClass = $sourceClass;
$this->labelField = $labelField;
- parent::__construct($name, $title, $this->getHierarchy($parentID), $value, $form, $emptyString);
+ parent::__construct($name, $title, $this->getHierarchy((int)$parentID), $value, $form, $emptyString);
}

public function setLabelField($field)

Cheers.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 September 2010 at 2:38am

Sorry about this, guys. This change was not supposed to be checked in. I was just testing a new feature. The new parameter should be at the end of the arguments, after $emptyString to make this backward compatible.

I'll make the adjustment and check it in now.

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Go to Top