1770 Posts in 495 Topics by 531 members
Blog Module
SilverStripe Forums » Blog Module » Overriding Blog Classes
Discuss the Blog Module.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 338 Views |
-
Overriding Blog Classes

21 March 2012 at 12:10pm
Hi,
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
<?php
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.
Regards,
Rodolfo -
Re: Overriding Blog Classes

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?
-
Re: Overriding Blog Classes

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
http://doc.silverstripe.org/sapphire/en/reference/dataobjectdecorator
Chur!
-
Re: Overriding Blog Classes

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....
-
Re: Overriding Blog Classes

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.
| 338 Views | ||
|
Page:
1
|
Go to Top |


