Jump to:

10931 Posts in 2614 Topics by 1810 members

All other Modules

SilverStripe Forums » All other Modules » Modularising my code stops ComplexTable from saving

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 693 Views
  • njprrogers
    Avatar
    Community Member
    23 Posts

    Modularising my code stops ComplexTable from saving Link to this post

    Hi,

    I am maintaining a large existing site and I am going to add create a new module to contain a new development.

    I have a ComplexTable Field maintaining a dataobject called Tip. I have added some page types to the mysite code and tested my functionality. There are no problems there.

    When I move the code to a new module in the root, everything looks the same until I come to save my page. I get no error returned but Silverstripe is no longer saving the dataobject relationship.

    My page class looks as follows:

    class FAQ extends Page {

    static $db = array(
    'RelatedFAQs' => 'HTMLText',
    );

       public static $has_one = array(
          'MyTip' => 'Tip'
       );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $tablefield = new HasOneComplexTableField(
    $this,
    'MyTip',
    'Tip',
    array(
    'TipName' => 'Tip Name',
    'TipContent' => 'Tip Content'
    ),
    'getCMSFields_forPopup'
    );
              $tablefield->setParentClass('FAQ');

    $fields->addFieldToTab( 'Root.Content.Tips', $tablefield );
    $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('RelatedFAQs'));

    return $fields;
    }
       

    }

    My dataobject looks as follows:

    class Tip extends DataObject {

       public static $db = array(
          'TipName' => 'Text',
          'TipContent' => 'HTMLText'
       );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();

    $fields->push( new TextField( 'TipName' ) );
    $fields->push( new HTMLEditorField( 'TipContent' ) );

    return $fields;
    }
       public static $has_many = array(
          'FAQs' => 'FAQ'
       );

    }

    Is this a known issue? Do I need to add anything in to my module config file? It is currently empty.

    Thanks in advance!

    Nick

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Modularising my code stops ComplexTable from saving Link to this post

    Has your module got a _config.php file in the root? SS won't parse the directory unless it has. Also you will need to run a ?flush=1 whenever you move classes around.

  • njprrogers
    Avatar
    Community Member
    23 Posts

    Re: Modularising my code stops ComplexTable from saving Link to this post

    Hi Willr,

    Thanks for getting back. As you know, a gentleman always flushes .

    I have three installations of this (there is one in UAT etc) and I got this issue in all three after a build, a flush etc.

    I have managed to get it working by changing the name of the field holding the relationship between the tip and the faq:

    }
    public static $has_many = array(
    'FAQs' => 'FAQ'
    );

    }


    got changed to

    }
    public static $has_many = array(
    'FAQ' => 'FAQ'
    );

    }


    and it worked.

    I think the relationship was somehow lost after the folder move.

    Thanks,

    Nick

  • njprrogers
    Avatar
    Community Member
    23 Posts

    Re: Modularising my code stops ComplexTable from saving Link to this post

    Hi,

    This error has re-occurred after initially working. It makes me think that my HasOneComplexTableField and the dataobject relationship is not defined correctly or something similar.

    This time, there has been no movement of the module classes or anything like that. I do not know why it stopped maintaining the relationship between the FAQ page and the Tip dataObject.

    When I click save / save and publish, the radio button which I have selected on the HasOneComplexTableField empties at the last moment.

    Again, I have done a few rebuilds / changed a few things. The first time I got it back working was when I rolled back all my changes and rebuilt with the original code:

    Can anyone see anything incorrect or incomplete here?

    class FAQ extends Page {

    static $db = array(
    'RelatedFAQs' => 'HTMLText',
    );

       public static $has_one = array(
          'MyTip' => 'Tip'
       );
       
    function getCMSFields() {
    $fields = parent::getCMSFields();

    $tablefield = new HasOneComplexTableField(
    $this,
    'MyTip',
    'Tip',
    array(
    'TipName' => 'Tip Name',
    'TipContent' => 'Tip Content'
    ),
    'getCMSFields_forPopup'
    );
              $tablefield->setParentClass('FAQ');

    $fields->addFieldToTab( 'Root.Content.Tips', $tablefield );
    $fields->addFieldToTab('Root.Content.Main', new HTMLEditorField('RelatedFAQs'));

    return $fields;
    }
       

    }

    class Tip extends DataObject {

       public static $db = array(
          'TipName' => 'Text',
          'TipContent' => 'HTMLText'
       );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();

    $fields->push( new TextField( 'TipName' ) );
    $fields->push( new HTMLEditorField( 'TipContent' ) );

    return $fields;
    }
       public static $has_many = array(
          'FAQ' => 'FAQ'
       );

    }

    693 Views
Page: 1
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.