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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

Modularising my code stops ComplexTable from saving


Go to End


4 Posts   1090 Views

Avatar
njprrogers

Community Member, 23 Posts

6 April 2011 at 10:04pm

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

Avatar
Willr

Forum Moderator, 5523 Posts

7 April 2011 at 11:44am

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.

Avatar
njprrogers

Community Member, 23 Posts

12 April 2011 at 2:47am

Edited: 12/04/2011 2:48am

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

Avatar
njprrogers

Community Member, 23 Posts

12 April 2011 at 11:23pm

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'
	);

}