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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

SS3 updateCMSFields issue when decorating extended Page class


Go to End


8 Posts   2882 Views

Avatar
nimesodelta

Community Member, 22 Posts

23 November 2012 at 1:14pm

Hi all,

I'm upgrading the shop module to SS3. https://github.com/burnbright/silverstripe-shop

I'm having an issue when I try to add a simple Decorator to my Product and then try using updateCMSFields... simply put, it doesn't work at all... not even a simple Debug::dump("working") does nothing. Here is my code.


class ProductVariationDecorator extends DataExtension{

	/**
	 * Adds variations specific fields to the CMS.
	 */
	public function updateCMSFields(FieldList $fields) {
	  Debug::dump("working");
	  $fields->addFieldToTab('Root.Variations',new HeaderField("Variation Attribute Types"));
	}

...

Avatar
copernican

Community Member, 189 Posts

30 November 2012 at 2:14am

Silly question but you did you add Object::add_extension('Product', 'ProductVariationDecorator'); to your _config.php?

I noticed in Product.php starting at line 79

$tempextvar = $this->get_static('SiteTree','runCMSFieldsExtensions');
$this->disableCMSFieldsExtensions();
$fields = parent::getCMSFields();
if($tempextvar){
	$this->enableCMSFieldsExtensions();
}

and on line 123

if($tempextvar){
	$this->extend('updateCMSFields', $fields);
}

perhaps that could be causing issues?

Avatar
nimesodelta

Community Member, 22 Posts

30 November 2012 at 7:57am

Hey ya IOTI,

Thanks heaps for your reply,

1. Yes _config is correct
2. the code in product is fine... I have tested by removing all of the code you mentioned, but still no luck.

I'll have another look in the next hour and see if I have any more luck.

All of my other decorators seem to work fine. Hmmm just found this in the changelogs for 3

http://doc.silverstripe.org/framework/en/changelogs/3.0.0

Settings-related fields move from SiteTree->getCMSFields() to new SiteTree->getSettingsFields() [getcmsfields] ¶
The fields and tabs are now split into two separate forms, which required a structural change to the underlying class logic. In case you have added or removed fields in the "Behaviour" or "Access" tab, please move these customizations to a new getSettingsFields() method. In case of SiteTree extension through updateCMSFields() and a decorator/extension, please use the new updateSettingsFields() instead.

?

Cheers Heaps
J

Avatar
copernican

Community Member, 189 Posts

30 November 2012 at 8:02am

Did you remove the

$this->extend('updateCMSFields', $fields); 

part as well? That one would need to stay :). Only asking because you said you removed "all of the code"

Avatar
nimesodelta

Community Member, 22 Posts

30 November 2012 at 9:51am

It's fine now. I'm so sorry IOTI :) I fixed something else and it seems fine now.

But yes, the whole:

//prevent calling updateCMSFields extend function too early
		$tempextvar = $this->get_static('SiteTree','runCMSFieldsExtensions');
		$this->disableCMSFieldsExtensions();
...
...
if($tempextvar){
			$this->extend('updateCMSFields', $fields);
		}

is a bit strange... I've taken it out and it seems fine. I'll have a chat with Jeremy (burnbright) and see if he feels we still need it for SS3

Thanks so much for your help.

J

Avatar
nimesodelta

Community Member, 22 Posts

30 November 2012 at 9:56am

and yes I left in $this->extend('updateCMSFields', $fields);

:)

J

Avatar
copernican

Community Member, 189 Posts

30 November 2012 at 9:57am

Cool, happy to hear you got it working!

Avatar
BenWu

Community Member, 97 Posts

22 May 2013 at 12:03am

I am using the silverstripe ecommerce module https://github.com/sunnysideup/silverstripe-ecommerce/

I got the same problem. There are 2 lines as mentioned by nimesodelta:

//prevent calling updateSettingsFields extend function too early


        $siteTreeFieldExtensions = $this->get_static('SiteTree','runCMSFieldsExtensions');
		$this->disableCMSFieldsExtensions();

i have to take it out as well