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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Blog Module /

Discuss the Blog Module.

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

custom BlogTree.php etc...


Go to End


4 Posts   1519 Views

Avatar
losqualo

Community Member, 17 Posts

4 September 2010 at 3:06am

Hi,

Blog 0.4.0 with SS 2.4

I have the blog folder installed at the correct place and I have my theme and theme_blog located in the themes folder. I also have my 'site' folder at the same level as 'blog' and 'themes'.

I'd like to make modifications to the php files that are located in blog/code.

I've tried copying the blog/code folder to

themes/theme_blog/code
themes/theme/code
site/code

The files are not being picked up from any location except blog/code.

I don't like having my modified versions of BlogTree.php, BlogHolder.php and so on, including some of the widgets (e.g. TagCloudWidget.php) being in the root blog folder because of the problems this will create at time of upgrading the blog. There must be a way of having local to the theme or site folder, but I've not found a solution that works... I could just be getting in a mess.

Where should I place local versions of files currently in blog/code?

Thanks in advance

Rob

Avatar
Willr

Forum Moderator, 5523 Posts

4 September 2010 at 8:02pm

You can't override code as simple as you do with themes. In PHP you can only have 1 name per class. If you want to make modifications to the blog you either need to subclass it or use decorators to hook into any extend() calls the module makes. If you're making extensive changes subclassing the blog classes you need would be the best way.

http://doc.silverstripe.org/dataobjectdecorator

Subclassing is as easy as making your own file say CustomBlogTree.php with

<?php

class CustomBlogTree extends BlogTree {

}

class CustomBlogTree_Controller extends BlogTree_Controller {

}
?>

And using CustomBlogTree pages in your CMS rather than BlogTree. You can even 'hide' the original BlogTree as an option in the create menu by using a static http://api.silverstripe.org/2.4/cms/SiteTree.html#var$hide_ancestor

Avatar
losqualo

Community Member, 17 Posts

4 September 2010 at 9:44pm

Hi,

Thanks for the guidance... I should of realised, but grew up coding before OOP, which remains utterly foreign to me most of the time...

You said:

>Subclassing is as easy as making your own file say CustomBlogTree.php with
>
><?php
>
>class CustomBlogTree extends BlogTree {
<
>}
>
>class CustomBlogTree_Controller extends BlogTree_Controller {
>
>}
>?>

Where would I put tat file... inside mysite/code is my immediate instinct, or does there need to be a blog folder created under mysite?

Thanks again

Rob

Avatar
Willr

Forum Moderator, 5523 Posts

4 September 2010 at 10:40pm

Mysite/code is the correct location for it.