7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » SimpleStreeDropdownBroken after last update
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 929 Views |
-
SimpleStreeDropdownBroken after last update

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
-
Re: SimpleStreeDropdownBroken after last update

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 -
Re: SimpleStreeDropdownBroken after last update

11 September 2010 at 3:30am Last edited: 11 September 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
-
Re: SimpleStreeDropdownBroken after last update

14 September 2010 at 3:43am
Still having the same problem....
Is nobody else experiencing this?
Cheers
Aram
-
Re: SimpleStreeDropdownBroken after last update

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 -
Re: SimpleStreeDropdownBroken after last update

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.
-
Re: SimpleStreeDropdownBroken after last update

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
| 929 Views | ||
| Go to Top | Next > |


