Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Decorater Problem

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

Page: 1
Go to End
Author Topic: 1203 Views
  • Bo_Einzeller
    Avatar
    Community Member
    18 Posts

    Decorater Problem Link to this post

    I have a page class and a subPage class which extends the page-class.
    now i want to decorate the page class with a decorater myPageDecorater.
    And the sub class with an other decorater mySubPageDecorater.

    In _config.php the decoraters are added like that:

    DataObject::add_extension('Page', 'myPageDecorater');
    DataObject::add_extension('SubPage ', 'mySubPageDecorater');

    The Problem is, the second Decorater is not added. No functions of the DecorationClass can be used...

    Is there any other way to add a specific decoration on SubPage?

    Thanks for you help, Michael

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: Decorater Problem Link to this post

    I'm assuming you didn't put that space after SubPage in your actual code?

    e.g. "SubPage " instead of "SubPage"

  • Bo_Einzeller
    Avatar
    Community Member
    18 Posts

    Re: Decorater Problem Link to this post

    You're right, that space isn't in the original code...
    for further informations, my classes are structed like this:
    Page.php

    class Page extends SiteTree { ... }

    SubPage.php

    class SubPage extends Page { ... }

    myPageDecorater.php

    class myPageDecorater extends DataObjectDecorator{
    public function TestFunction(){
    return "TestFunction of myPageDecorater ";
    }
    }

    mySubPageDecorater.php

    class mySubPageDecorater extends DataObjectDecorator{
    public function AnotherTestFunction(){
    return "TestFunction of mySubPageDecorater ";
    }
    }

    _config.php

    ...
    DataObject::add_extension('Page', 'myPageDecorater');
    DataObject::add_extension('SubPage', 'mySubPageDecorater');
    ...

    TestFunction is accessible on both classes, but i can't call AnotherTestFunction.

  • jhirm
    Avatar
    Community Member
    21 Posts

    Re: Decorater Problem Link to this post

    I'm having a similar problem, so I figured I'd give this thread a bump...

    I want to decorate the CalendarEvent class from the Event module, which extends the Page class directly. I've created the extension class:

    class MemberEventRole extends DataObjectDecorator {
    ...
    }

    and added the extension in the _config.php file of my module:

    DataObject::add_extension("CalendarEvent", "MemberEventRole");

    The decoration isn't working. Is there something about the order in which DataObjects load that could be causing a problem here? I'm also extending the core Member class in the same _config.php file, and it's working fine...

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