Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » Editing RedirectorPage.php - Bad Idea?

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

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

Page: 1
Go to End
Author Topic: 1092 Views
  • LinseyM
    Avatar
    Community Member
    99 Posts

    Editing RedirectorPage.php - Bad Idea? Link to this post

    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

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Editing RedirectorPage.php - Bad Idea? Link to this post

    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!

  • IOTI
    Avatar
    Community Member
    189 Posts

    Re: Editing RedirectorPage.php - Bad Idea? Link to this post

    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.

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Editing RedirectorPage.php - Bad Idea? Link to this post

    excellent thanks - i will give it a try

  • LinseyM
    Avatar
    Community Member
    99 Posts

    Re: Editing RedirectorPage.php - Bad Idea? Link to this post

    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

    1092 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.