Jump to:

23484 Posts in 18977 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » SS3 updateCMSFields issue when decorating extended Page class

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

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

Page: 1
Go to End
Author Topic: 1053 Views
  • nimesodelta
    Avatar
    Community Member
    18 Posts

    SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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"));
       }

    ...

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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?

  • nimesodelta
    Avatar
    Community Member
    18 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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"

  • nimesodelta
    Avatar
    Community Member
    18 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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

  • nimesodelta
    Avatar
    Community Member
    18 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

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

    J

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    Cool, happy to hear you got it working!

  • BenWu
    Avatar
    Community Member
    90 Posts

    Re: SS3 updateCMSFields issue when decorating extended Page class Link to this post

    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

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