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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Editing RedirectorPage.php - Bad Idea?


Go to End


5 Posts   1630 Views

Avatar
LinseyM

Community Member, 99 Posts

24 November 2010 at 9:12am

Hi all,

I would like the option on a redirector page to have a checkbox where the user can select whether or not the redirector should open in a new window, e.g. to go to an external blog without leaving the site behind.

I did look at code for "if is a redirector page / open in new tab", but that won't work as its only specific pages that I want to open in new window / tab.

I was considering adding a checkbox option in the RedirectorPage.php file, e.g.

$fields->addFieldToTab('Root.Content.Main', new CheckboxField('OpenInNewWindows), '');

...but I was worried that this was messing with the sapphire core, and therefore not a good idea.

Just looking for an expert opinion. thanks,

Linsey

Avatar
LinseyM

Community Member, 99 Posts

24 November 2010 at 9:30am

along the same lines, would it be dodgy to add another few fields in the "site properties / config"? (you know the one at the top of the site tree where you have the site name, tagline and option to choose theme)

I'd like to have a text box where client can add their phone number & also one for address, as these are currently hard-coded into the template (at the base next to the legal info) and it would be nice for them to be able to change these themselves if need be - eg they are moving office next month)

This would involve me adding af few new lines of code to sapphire > core > model > SiteConfig.php
I know it works as I did try it on a test site, but I am worried about doing this on a live site as in case it might end up being catastrophic if we upgrade the site or something!

Thanks guys!

Avatar
copernican

Community Member, 189 Posts

25 November 2010 at 5:02am

If you want to add extra fields to 'site properties/config' you can do this. in mysite/code create a new file called SiteConfigExtension.php

<?php
class SiteConfigExtension extends Extension {
    static public function extraStatics() {
        return array(
                         'db'=>array(
                                    'PhoneNumber'=>'Text'
                                )
                    );
    }
    
    public function updateCMSFields(&$fields) {
        $fields->addFieldToTab('Root.Main',new TextField('PhoneNumber','Phone Number'));
    }
}
?>

Also in _config.php it's necessary to add the following

Object::add_extension('SiteConfig', 'SiteConfigExtension');

I believe a similar approach could be used for RedirectorPage.php. Create a RedirectorPageExtension.php file in mysite/code, add the field(s) you desire and add the Object:add_extension('RedirectorPage', 'RedirectorPageExtension') to _config.php.

Avatar
LinseyM

Community Member, 99 Posts

25 November 2010 at 7:54am

excellent thanks - i will give it a try

Avatar
LinseyM

Community Member, 99 Posts

30 November 2010 at 5:14am

Hi there,

Been trying to get this to work, but as soon as I add this line:

Object::add_extension('SiteConfig', 'SiteConfigExtension');

to my _config.php file and try to rebuild / load a page I am just getting a server 500 error.

Unfortunatly I cannot get any more details than that about the error. Was wondering if there could be something obvious causing the error? (Am using 2.4.3)

Thanks again :)