Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » SimpleTreeDropdownField makes Problems

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: 2524 Views
  • Andre
    Avatar
    Community Member
    125 Posts

    SimpleTreeDropdownField makes Problems Link to this post

    Hi there, I still have problems with SimpleTreeDropdownFiled and TreeDropdownField inside the Javascript Popup.
    I have a collection of the following Class:

    class Overview extends DataObject{
          static $db = array (
             'LinkTitle' => 'Text',
             'LinkTeaser' => 'Text'
          );

          static $has_one = array (
             'OverviewTarget' => 'SiteTree'
          );

          public function getCMSFields_forPopup(){
             return new FieldSet(
                new TextField('LinkTitle', "Link Titel:"),
                new TextField('LinkTeaser', "Link Teaser:"),
                new SimpleTreeDropdownField('OverviewTarget', "Link Ziel:", 'SiteTree')
             );
          }
    }

    The Problem is, that the value from the SimpleTreeDropdownField isn't saved.
    I'm trying to read OververviewTarget and OverviewTargetID but both values are empty or always showing the value "1".
    I also tried to use the Following line (as needed in TreeDropdoewnFiled)

    new SimpleTreeDropdownField('OverviewTargetID', "Link Ziel:", 'SiteTree')


    but when using OverviewTargetID insted of OverviewTarget the Dropdown doesn't appear in the Popup.
    The same is happening to TreeDropdownField. It doesn't appear when using OverviewTargetID and it's not saving the value when using OverviewTarget.

    What am I doing wrong, or is there just a simple error in Silverstripe 2.3.2 / 2.3.3?

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    It should definitely be OverviewTargetID. Looks like you may have set up your model wrong. What page does the DataObject belong to? If the page has_many Overview, then your overview needs to has_one Page, and that has to be the first entry in your has_one

    static $has_one = array (
    'ObjectHolder' => 'ObjectHolder',
    'OverviewTarget' => 'SiteTree'
    );

  • Andre
    Avatar
    Community Member
    125 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    Hi, this is the Model:

    <?php

    class StartPage extends ExtendedPage {

       public static $has_one = array(
          'LeftImage' => 'Image',
          'RightImage' => 'Image'
       );

       static $has_many = array (
          'Overviews' => 'Overview'
       );

       public function getCMSFields(){
          
          $fields = parent::getCMSFields();
          $fields->addFieldToTab("Root.Content.Images", new ImageField('LeftImage', 'Linkes Bild'));
          $fields->addFieldToTab("Root.Content.Images", new ImageField('RightImage', 'Rechtes Bild'));
          $fields->addFieldToTab('Root.Content.Ueberuns', new DataObjectManager(
             $this, // Controller
             'Overviews', // Source name
             'Overview', // Source class
             array(
                'LinkTitle' => 'LinkTitle',
                'LinkTeaser' => 'LinkTeaser'
             ),
             'getCMSFields_forPopup'
          ));

          return $fields;
       }

    }

    class StartPage_Controller extends ExtendedPage_Controller {

    }

    ?>

    Do you mean, that I should add

    static $has_one = array (
    'StartPage' => 'StartPage',
    'OverviewTarget' => 'SiteTree'
    );

    to the Overview Object?

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    Yeah, otherwise there's no database relation. The foreign key goes on the has_one object, not on the has_many object. If you run a build with that code you'll see you get a new field.

  • Andre
    Avatar
    Community Member
    125 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    Well, damn, it works. Many thanks. I was a week chewing on this Problem and in the end it was a stupid small mistake. I realy should work a lot more with Silverstripe to have these Concepts in Mind.

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    I have the exact same problem: MasterPage edits a collection of DetailObjects, which include a caption and a target page ID. The target page value from the SimpleTreeDropdownField isn't saved. I've been over the code again and again but can't spot what I'm doing wrong. Any ideas?

    The query looks like this. Note the DetailObjectTargetID field is not updated,

    INSERT INTO "DetailObject" ("Created") VALUES (NOW())
    SELECT "ID" FROM "DetailObject" WHERE "ID" = 2
    UPDATE "DetailObject" SET "ClassName" = 'DetailObject', "Caption" = 'Marker', "MasterPageID" = 11, "LastEdited" = '2010-07-01 15:00:50', "Created" = '2010-07-01 15:00:50' where "ID" = 2

    After the query, the data looks like this:

    ID    ClassName    Created    LastEdited    Caption    MasterPageID    DetailObjectTargetID
    2    DetailObject    2010-07-01 15:00:50    2010-07-01 15:00:50    Marker    11    0

    ========== MasterPage.php ==========

    <?php
    /**
    * Defines the HomePage page type
    */

    class MasterPage extends Page {
       static $db = array(
       );

       static $has_many = array(
          'DetailObjects' => 'DetailObject'
       );

       public function getCMSFields() {
          $fields = parent::getCMSFields();

          // Note: The array defines the fields shown in the grid
          $tablefield = new DataObjectManager(
             $this,
             'DetailObjects',
             'DetailObject',
             array(
                'Caption' => 'Caption'
                ),
             'getCMSFields_forPopup'
          );
          $fields->addFieldToTab( 'Root.Content.Detail', $tablefield );

          return $fields;
       }
    }

    class MasterPage_Controller extends Page_Controller {

       public function init() {
          parent::init();
       }
    }
    ?>

    ========== DetailObject.php ==========

    <?php

    class DetailObject extends DataObject {

       public static $db = array(
          'Caption' => 'Text'
       );

       public static $has_one = array(
          'MasterPage' => 'MasterPage',
          'DetailObjectTarget' => 'SiteTree'
       );

       // Define the fields shown in the record editor popup
       public function getCMSFields_forPopup() {
          return new FieldSet(
             new TextField('Caption'),
             new SimpleTreeDropdownField('DetailObjectTargetId', "Target page", 'SiteTree')
          );
       }
    }
    ?>

    Cheeky 2nd question: Does DOM work with TreeDropdownField? I'm concerned about scalability - if the site has too many pages then SimpleTreeDropdownField may become unusable.

    Thanks,
    Jules

  • UncleCheese
    Avatar
    4085 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    DetailObjectTargetId

    Don't you mean DetailObjectTargetID?

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: SimpleTreeDropdownField makes Problems Link to this post

    Nice one boss, that's it! Thanks!

    Is there any way of getting warning/error messages when I make that kind of mistake? SilverStripe seems to fail quietly - either ignoring errors or generating a blank screeen, even with &isDev=1.

    2524 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.