Jump to:

7937 Posts in 1537 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SimpleStreeDropdownBroken after last update

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2
Go to End
Author Topic: 1169 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    SimpleStreeDropdownBroken after last update Link to this post

    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

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    Still having the same problem....

    Is nobody else experiencing this?

    Cheers

    Aram

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

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

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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    Awesome, thanks!

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    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.

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleStreeDropdownBroken after last update Link to this post

    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

    1169 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.