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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

SimpleStreeDropdownBroken after last update


Go to End
Reply

10 Posts   1223 Views

Avatar
Carbon Crayon

10 September 2010 at 11:09pm Community Member, 598 Posts

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

11 September 2010 at 2:10am 4085 Posts

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

11 September 2010 at 3:30am (Last edited: 11 September 2010 3:31am), Community Member, 598 Posts

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

14 September 2010 at 3:43am Community Member, 598 Posts

Still having the same problem....

Is nobody else experiencing this?

Cheers

Aram

Avatar
UncleCheese

14 September 2010 at 6:49am 4085 Posts

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

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

Avatar
Carbon Crayon

14 September 2010 at 8:22am Community Member, 598 Posts

Awesome, thanks!

Avatar
Pigeon

16 September 2010 at 1:58am Community Member, 243 Posts

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

16 September 2010 at 2:38am 4085 Posts

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