Snippets - Little bits of code to make you happy
Remove theme selector from SiteConfig
Tweet15 October 2010 | | | Supports v2.4
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
6 Comments
RSS feed for comments on this page RSS feed for all comments
Chris Hope
15/10/2010 2:14am (3 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 (3 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 (3 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 (3 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 (2 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 (12 months 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.