Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » 2.4 - DOM in SiteConfig not working for me

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1 2 3 4 5
Go to End
Author Topic: 6075 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    2.4 - DOM in SiteConfig not working for me Link to this post

    EDIT - Ok so I just tried CTF and it gave me this error on save:

    Fatal error: Call to a member function getComponents() on a non-object in /home/aabfbo/public_html/dev/sapphire/forms/ComplexTableField.php on line 661

    Which means this line is returning nothing:

    $parentRecord = DataObject::get_by_id($data['ctf']['parentClass'], (int) $data['ctf']['sourceID']);

    So I guess this is not a DOM issue, but perhaps you will be able to shed a little more light on it than I can? Looks like it's not getting the ID from the SiteConfig DataObject.... Thanks UC

    /EDIT

    Hi UC

    I have been testing out using the DOM in the SiteConfig of 2.4 Rc1 using the DOM r393. here is my code:

    DataObject:

    <?php
    class Link extends DataObject {

       static $has_one = array (
          'SiteConfig' => 'SiteConfig',
          'LinkedPage' => 'SiteTree'
       );

       static $summary_fields = array(
          'LinkedPage.Title' => 'Linked Page'
       );

       public function getCMSFields_forPopup()
       {
          $fields = new FieldSet();
          
          $fields->push(new SimpleTreeDropdownField('LinkedPageID', 'Link to Internal Page'));

          return $fields;
       }

    }

    CustomSiteConfig.php

    <?php

    class CustomSiteConfig extends Extension {
       
       function extraStatics() {
          return array(
             'has_many' => array(
                'Links' => 'Link'
             )
          );
       }

       public function updateCMSFields(FieldSet &$fields) {
          
          $manager = new DataObjectManager(
             $this->owner,
             'Links',
             'Link',
             Link::$summary_fields,
             'getCMSFields_forPopup'         
          );   
          $fields->addFieldToTab("Root.InfoMenu", $manager);
          
       }

    }

    It all appears to work fine until you add a dataobject. It adds the object to the database and it shows up in the DOM, however the relation ID on the DO (SiteConfigID) is not set and stays 0. So for some reason all the Link Objects show up in the table, yet none of them are actually attached to the SiteConfig so when try to use them in the templates nothing is returned.

    If I am honest I am not totally sure if this should work, but it would be great if it could as having a DOM in siteconfig would be really great and I assume it's not all that different to having it in Model admin which seems to work fine.

    Oh one other thing I noticed, the SimpleTreeDropdown does not seem to display properly in 2.4, instead of having an indentation, it displays like:


    Page
    &nbsp;&nbsp;SubPage

    Cheers

    Aram

    www.SSBits.com - SilverStripe tutorials, tips and other bits

  • UncleCheese
    Avatar
    4085 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    You probably need to use setParentClass() to make sure the foreign key gets set?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    Hey UC, thanks for the (as usual) fast response.

    Unfortunately it doesn't seem to make a difference. My DOM def now looks like this:

          $manager = new DataObjectManager(
             $this->owner,
             'Links',
             'Link',
             Link::$summary_fields,
             'getCMSFields_forPopup'
          );   
          $manager->setParentClass('SiteConfig');
          $fields->addFieldToTab("Root.Links", $manager);   

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    Has anyone else got DOM or CTF working within the site config?

    I am writing a post for SSBits about SiteConfig so would be nice to include DOM in that if it's possible....

    Aram

    www.SSBits.com - SilverStripe Tutorials, tips and other bits

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    Hey Aram,

    I've had a similar problem before when trying to relate an item managed by DOM to another DO (rather than the page holding it). ParentID seems to get set as the holding page all the time.

    So i had to extend the functionality a litte. (Uncy, might be worth adding to the core of DOM? It can be helpful to specifically define the ID of the parent you want).

    class BBComplexTableField extends ComplexTableField {
       
       /**
        * Set Source ID
        *
        * sets the source ID for the ComplexTableField
        *
        * @param int $val The ID of the source object
        */
       function setSourceID($val) {
          if (is_numeric($val)) {
             $this->sourceID = $val;
          }
       }
       
       /**
        * Source ID
        *
        * returns the sourceID as previously set or passed as a form field
        *
        * @return int the ID of the source object
        */
       function sourceID() {
          if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
             return $this->sourceID;
          }
          return parent::sourceID();
       }
    }

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    Great thanks Pigeon! That worked perfectly.

    Tutorial can be found here:
    http://ssbits.com/2-4-working-with-siteconfig/

    Thanks again

    Aram

    www.SSBits.com - SilverStripe tutorials, tips and other bits

  • Deklin
    Avatar
    Community Member
    16 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    Thank you both for this thread.

    Aram, I found your tutorial useful and it works perfectly with the third-party data object manager however I cannot get it to work with the native ComplexTableField.

    <?php

    // Download this code with related files here:
    // http://sites.google.com/site/adsffadsf/Home/CustomSiteConfig.zip

    class CustomSiteConfig extends Extension {

    function extraStatics() {
    return array('has_many' => array('Links' => 'Link'));
    }

    public function updateCMSFields(FieldSet & $fields) {
    $fields = parent::getCMSFields();
    $tablefield = new HasManyComplexTableField($this->owner, 'Links', 'Link', array('Link' => 'Link', 'Text' => 'Link Text',), 'getCMSFields_forPopup');
    $tablefield->setSourceID($this->owner->ID);
    $fields->addFieldToTab("Root.FooterLinks", $tablefield);
    }

    function setSourceID($val) {
    if (is_numeric($val)) {
    $this->sourceID = $val;
    }
    }

    function sourceID() {
    if (isset($this->sourceID) && $this->sourceID !== null && is_numeric($this->sourceID)) {
    return $this->sourceID;
    }
    return parent::sourceID();
    }
    }

    ?>

  • UncleCheese
    Avatar
    4085 Posts

    Re: 2.4 - DOM in SiteConfig not working for me Link to this post

    It's a little odd that your sourceID() functions are in CustomSiteConfig, but you're calling them on a CTF object. ???

    6075 Views
Page: 1 2 3 4 5
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.