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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Blog Module /

Discuss the Blog Module.

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

Overriding Blog Classes

Go to End

5 Posts   1292 Views


Community Member, 11 Posts

21 March 2012 at 12:10pm


I'm trying to override a function in TagCloudWidget using a custom class but SS seems to ignore this new file.

Basically what I did was:

- I created a new class in /mysite/code/CustomTagCloudWidget.php with the following structure


class CustomTagCloudWidget extends TagCloudWidget {

    function TagsCollection() {
       // new stuff


- Added the useCustomClass method to my _config.php file

Object::useCustomClass('TagCloudWidget', 'CustomTagCloudWidget', true);

Am I missing something?

Thank you in advance.



Community Member, 11 Posts

21 March 2012 at 12:52pm

I just tried to override the getCMSFields() method for the BlogHolder class and I'm getting the same behavior.

Is there a special way to override module classes?


Community Member, 116 Posts

21 March 2012 at 2:58pm

Mr Rodolfo,

I could be wrong, but I have run in to this in the past. It's because only objects instantiated using Object::create can be overridden using Object::useCustomClass

Instead of ::useCustomClass, try ::add_extension



Community Member, 11 Posts

22 March 2012 at 8:34am

Hi Nova,

Thanks for the reply.

I gave it a go but it didn't work. After reading the docs more closely I realized that this won't do what I want, which is replace the behavior of an existing method. The use of the decorator pattern allows me to dynamically add methods to an existing object but not override them.

There must be a way to override classes in the Blog module....


Community Member, 116 Posts

22 March 2012 at 8:45am

Hi Rodolfo,

If you extend the class you wish to extend in Blog, then use add_extension in mysite/_config.php, then... you should be able to redeclare the class you wish to override, rewrite the class to follow your new logic, then the old class should be ignored?

Could be wrong but it may work.