SSbits - Home page
Site by Carbon Crayon
Submit a Post >

Snippets - Little bits of code to make you happy

Remove theme selector from SiteConfig

2.4 has introduced the SiteConfig, which by default allows the user to switch themes - if they exist.

It's incredibly useful to have this functionality built-in now, but for those that only have one theme for a site, it's a bit of unnecessary clutter. Here is how to remove it by using a decorator

class CustomSiteConfig extends DataObjectDecorator {
	...
	function updateCMSFields(FieldSet &$fields) {
		...
		$fields->removeByName('Theme');
		
	}
	...
}

Then simply apply your decorator from the _config.php file:

DataObject::add_extension('SiteConfig', 'CustomSiteConfig');

For more info on SiteConfig, see this post: Working with SiteConfig

Daniel Hensby avatar

Daniel Hensby

Dan runs a website development company called Better Brief. Better Brief specialise in SilverStripe websites and takes an active role in the UK SilverStripe community, attending SS Meetups and even presenting at them.

  • Chris Hope
    15/10/2010 2:14am (4 years ago)

    Funnily enough I'd done exactly this myself on one of my sites about half an hour before you posted it. If you want to get rid of the other ones too, because you don't use them anywhere:

    $fields->removeByName('Title');
    $fields->removeByName('Tagline');

  • Marcus Dalgren
    15/10/2010 8:16am (4 years ago)

    Yes removing the theme selector makes alot of sense in most cases. SiteConfig is also a great place to put global information about the site so that you don't clutter up your homepage.

  • Jeroen Marechal
    20/10/2010 10:23pm (4 years ago)

    Yes, I think the theme selection is a bit unnecessary. Never actually used it eithe. Better of using the space for some global information

  • MRKDevelopment
    21/11/2010 11:23am (4 years ago)

    Its only useful when doing multi site setups.

    This is a great tip though, customer generally will break anything if you give them access too.

  • Darren-Lee
    09/04/2011 1:07pm (3 years ago)

    Thanks, Dan. Since reading your post, I use this all the time - it helps to clean up the admin interface - one less thing for the client to get confused about!

  • gav
    04/07/2012 7:55am (2 years ago)

    This is the SilverStripe 3 version of this:

    _config.php
    Object::add_extension('SiteConfig', 'SiteConfigDecorator');

    SiteConfigDecorator.php

    <?php
    class SiteConfigDecorator extends DataExtension {

    static $db = array();

    public function updateCMSFields(FieldList $fields) {
    $fields->removeByName('Theme');
    $fields->removeByName('Tagline');
    }

    function __construct() {
    parent::__construct();
    }

    }

Post a comment ...

You cannot post comments until you have logged in. Login Here.

Advertisement

Site of the Month

Find SSbits on

Top Contributers

Rank Avatar Name
1 article image Aram Balakjian
2 article image Daniel Hensby
3 article image Marcus Dalgren
4 article image Hamish Campbell
5 article image Ty Barho
6 article image Martijn van Nieuwenhoven
7 article image Darren-Lee
8 article image Roman Schmid
9 article image Matt Clegg
10 article image dalesaurus

View full leaderboard


Advertisement