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.

Data Model Questions

Decorater Problem


Reply

4 Posts   1211 Views

Avatar
Bo_Einzeller

22 March 2009 at 4:40am Community Member, 18 Posts

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

Avatar
Sean

23 March 2009 at 9:24pm Forum Moderator, 921 Posts

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

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

Avatar
Bo_Einzeller

23 March 2009 at 10:15pm (Last edited: 23 March 2009 10:56pm), Community Member, 18 Posts

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.

Avatar
jhirm

1 May 2009 at 9:13am Community Member, 21 Posts

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