Skip to content

Commit

Permalink
API Marked statics private, use Config API instead (#8317)
Browse files Browse the repository at this point in the history
See "Static configuration properties are now immutable, you must use Config API." in the 3.1 change log for details.
  • Loading branch information
chillu committed Mar 24, 2013
1 parent f55bd9d commit 3334eaf
Show file tree
Hide file tree
Showing 253 changed files with 2,086 additions and 1,533 deletions.
4 changes: 3 additions & 1 deletion _config/config.yml
Expand Up @@ -3,4 +3,6 @@ Name: coreconfig
---
Upload:
# Replace an existing file rather than renaming the new one.
replaceFile: false
replaceFile: false
MySQLDatabase:
connection_charset: utf8
4 changes: 2 additions & 2 deletions admin/code/AdminRootController.php
Expand Up @@ -8,15 +8,15 @@ class AdminRootController extends Controller {
* The url base that all LeftAndMain derived panels will live under
* Won't automatically update the base route if you change this - that has to be done seperately
*/
static $url_base = 'admin';
private static $url_base = 'admin';

/**
* @var string
* @config
* The LeftAndMain child that will be used as the initial panel to display if none is selected (i.e. if you
* visit /admin)
*/
static $default_panel = 'SecurityAdmin';
private static $default_panel = 'SecurityAdmin';

/**
* @var array
Expand Down
10 changes: 5 additions & 5 deletions admin/code/CMSBatchActionHandler.php
Expand Up @@ -8,9 +8,10 @@
*/
class CMSBatchActionHandler extends RequestHandler {

static $batch_actions = array();
/** @config */
private static $batch_actions = array();

static $url_handlers = array(
private static $url_handlers = array(
'$BatchAction/applicablepages' => 'handleApplicablePages',
'$BatchAction/confirmation' => 'handleConfirmation',
'$BatchAction' => 'handleBatchAction',
Expand Down Expand Up @@ -40,9 +41,8 @@ class CMSBatchActionHandler extends RequestHandler {
*/
public static function register($urlSegment, $batchActionClass, $recordClass = 'SiteTree') {
if(is_subclass_of($batchActionClass, 'CMSBatchAction')) {
self::$batch_actions[$urlSegment] = array(
'class' => $batchActionClass,
'recordClass' => $recordClass
Config::inst()->update('CMSBatchActionHandler', 'batch_actions',
array($urlSegment => array('class' => $batchActionClass, 'recordClass' => $recordClass))
);
} else {
user_error("CMSBatchActionHandler::register() - Bad class '$batchActionClass'", E_USER_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion admin/code/CMSMenu.php
Expand Up @@ -219,7 +219,7 @@ public static function clear_menu() {
* {@link remove_menu_item}. Also used as a CSS-class for icon customization.
* @param string $menuTitle Localized title showing in the menu bar
* @param string $url A relative URL that will be linked in the menu bar.
* Make sure to add a matching route via {@link Director::addRules()} to this url.
* Make sure to add a matching route via {@link Director::$rules} to this url.
* @param string $controllerClass The controller class for this menu, used to check permisssions.
* If blank, it's assumed that this is public, and always shown to users who
* have the rights to access some other part of the admin area.
Expand Down
8 changes: 4 additions & 4 deletions admin/code/CMSProfileController.php
@@ -1,12 +1,12 @@
<?php
class CMSProfileController extends LeftAndMain {

static $url_segment = 'myprofile';
private static $url_segment = 'myprofile';

static $menu_title = 'My Profile';
private static $menu_title = 'My Profile';

static $required_permission_codes = false;
static $tree_class = 'Member';
private static $required_permission_codes = false;
private static $tree_class = 'Member';

public function getResponseNegotiator() {
$neg = parent::getResponseNegotiator();
Expand Down
121 changes: 78 additions & 43 deletions admin/code/LeftAndMain.php
Expand Up @@ -16,63 +16,72 @@ class LeftAndMain extends Controller implements PermissionProvider {
* Note that if this is changed, many javascript
* behaviours need to be updated with the correct url
*
* @config
* @var string $url_base
*/
static $url_base = "admin";
private static $url_base = "admin";

/**
* The current url segment attached to the LeftAndMain instance
*
* @config
* @var string
*/
static $url_segment;
private static $url_segment;

/**
* @config
* @var string
*/
static $url_rule = '/$Action/$ID/$OtherID';
private static $url_rule = '/$Action/$ID/$OtherID';

/**
* @config
* @var string
*/
static $menu_title;
private static $menu_title;

/**
* @config
* @var string
*/
static $menu_icon;
private static $menu_icon;

/**
* @config
* @var int
*/
static $menu_priority = 0;
private static $menu_priority = 0;

/**
* @config
* @var int
*/
static $url_priority = 50;
private static $url_priority = 50;

/**
* A subclass of {@link DataObject}.
*
* Determines what is managed in this interface, through
* {@link getEditForm()} and other logic.
*
* @config
* @var string
*/
static $tree_class = null;
private static $tree_class = null;

/**
* The url used for the link in the Help tab in the backend
*
*
* @config
* @var string
*/
static $help_link = 'http://3.0.userhelp.silverstripe.org';
private static $help_link = 'http://3.0.userhelp.silverstripe.org';

/**
* @var array
*/
static $allowed_actions = array(
private static $allowed_actions = array(
'index',
'save',
'savetreenode',
Expand All @@ -88,34 +97,45 @@ class LeftAndMain extends Controller implements PermissionProvider {
);

/**
* @config
* @var Array Codes which are required from the current user to view this controller.
* If multiple codes are provided, all of them are required.
* All CMS controllers require "CMS_ACCESS_LeftAndMain" as a baseline check,
* and fall back to "CMS_ACCESS_<class>" if no permissions are defined here.
* See {@link canView()} for more details on permission checks.
*/
static $required_permission_codes;
private static $required_permission_codes;

/**
* @config
* @var String Namespace for session info, e.g. current record.
* Defaults to the current class name, but can be amended to share a namespace in case
* controllers are logically bundled together, and mainly separated
* to achieve more flexible templating.
*/
static $session_namespace;
private static $session_namespace;

/**
* Register additional requirements through the {@link Requirements} class.
* Used mainly to work around the missing "lazy loading" functionality
* for getting css/javascript required after an ajax-call (e.g. loading the editform).
*
* @var array $extra_requirements
* @config
* @var array
*/
protected static $extra_requirements = array(
'javascript' => array(),
'css' => array(),
'themedcss' => array(),
);
private static $extra_requirements_javascript = array();

/**
* @config
* @var array See {@link extra_requirements_javascript}
*/
private static $extra_requirements_css = array();

/**
* @config
* @var array See {@link extra_requirements_javascript}
*/
private static $extra_requirements_themedCss = array();

/**
* @var PjaxResponseNegotiator
Expand Down Expand Up @@ -161,13 +181,13 @@ public function canView($member = null) {
public function init() {
parent::init();

SSViewer::setOption('rewriteHashlinks', false);
Config::inst()->update('SSViewer', 'rewrite_hash_links', false);

// set language
$member = Member::currentUser();
if(!empty($member->Locale)) i18n::set_locale($member->Locale);
if(!empty($member->DateFormat)) i18n::set_date_format($member->DateFormat);
if(!empty($member->TimeFormat)) i18n::set_time_format($member->TimeFormat);
if(!empty($member->DateFormat)) i18n::config()->date_format = $member->DateFormat;
if(!empty($member->TimeFormat)) i18n::config()->time_format = $member->TimeFormat;

// can't be done in cms/_config.php as locale is not set yet
CMSMenu::add_link(
Expand Down Expand Up @@ -231,8 +251,8 @@ public function init() {
// Use theme from the site config
if(class_exists('SiteConfig') && ($config = SiteConfig::current_site_config()) && $config->Theme) {
$theme = $config->Theme;
} elseif(SSViewer::current_theme()) {
$theme = SSViewer::current_theme();
} elseif(Config::inst()->get('SSViewer', 'theme')) {
$theme = Config::inst()->get('SSViewer', 'theme');
} else {
$theme = false;
}
Expand Down Expand Up @@ -335,22 +355,26 @@ public function init() {
}

// Custom requirements
foreach (self::$extra_requirements['javascript'] as $file) {
Requirements::javascript($file[0]);
$extraJs = $this->stat('extra_requirements_javascript');

if($extraJs) foreach($extraJs as $file => $config) {
Requirements::javascript($file);
}
foreach (self::$extra_requirements['css'] as $file) {
Requirements::css($file[0], $file[1]);
$extraCss = $this->stat('extra_requirements_css');
if($extraCss) foreach($extraCss as $file => $config) {
Requirements::css($file, isset($config['media']) ? $config['media'] : null);
}
foreach (self::$extra_requirements['themedcss'] as $file) {
Requirements::themedCSS($file[0], $file[1]);
$extraThemedCss = $this->stat('extra_requirements_themedcss');
if($extraThemedCss) foreach ($extraThemedCss as $file => $config) {
Requirements::themedCSS($file, isset($config['media']) ? $config['media'] : null);
}

$dummy = null;
$this->extend('init', $dummy);

// The user's theme shouldn't affect the CMS, if, for example, they have replaced
// TableListField.ss or Form.ss.
SSViewer::set_theme(null);
Config::inst()->update('SSViewer', 'theme', null);
}

public function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
Expand Down Expand Up @@ -430,11 +454,15 @@ public function ShowSwitchView() {
*/
public function Link($action = null) {
// Handle missing url_segments
if(!$this->stat('url_segment', true)) self::$url_segment = $this->class;
if($this->config()->url_segment) {
$segment = $this->config()->get('url_segment', Config::FIRST_SET);
} else {
$segment = $this->class;
};

$link = Controller::join_links(
$this->stat('url_base', true),
$this->stat('url_segment', true),
$segment,
'/', // trailing slash needed if $action is null!
"$action"
);
Expand Down Expand Up @@ -1441,39 +1469,43 @@ public function SiteConfig() {
* The href for the anchor on the Silverstripe logo.
* Set by calling LeftAndMain::set_application_link()
*
* @config
* @var String
*/
static $application_link = 'http://www.silverstripe.org/';
private static $application_link = 'http://www.silverstripe.org/';

/**
* Sets the href for the anchor on the Silverstripe logo in the menu
*
* @param String $link
*/
public static function set_application_link($link) {
self::$application_link = $link;
Deprecation::notice('3.2', 'Use the "LeftAndMain.application_link" config setting instead');
Config::inst()->update('LeftAndMain', 'application_link', $link);
}

/**
* @return String
*/
public function ApplicationLink() {
return self::$application_link;
return $this->stat('application_link');
}

/**
* The application name. Customisable by calling
* LeftAndMain::setApplicationName() - the first parameter.
*
*
* @config
* @var String
*/
static $application_name = 'SilverStripe';
private static $application_name = 'SilverStripe';

/**
* @param String $name
*/
public static function setApplicationName($name) {
self::$application_name = $name;
Deprecation::notice('3.2', 'Use the "LeftAndMain.application_name" config setting instead');
Config::inst()->update('LeftAndMain', 'application_name', $name);
}

/**
Expand All @@ -1482,7 +1514,7 @@ public static function setApplicationName($name) {
* @return string
*/
public function getApplicationName() {
return self::$application_name;
return $this->stat('application_name');
}

/**
Expand Down Expand Up @@ -1571,7 +1603,8 @@ public function providePermissions() {
* Filenames should be relative to the base, eg, FRAMEWORK_DIR . '/javascript/loader.js'
*/
public static function require_javascript($file) {
self::$extra_requirements['javascript'][] = array($file);
Deprecation::notice('3.2', 'Use "LeftAndMain.extra_requirements_javascript" config setting instead');
Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array($file => array()));
}

/**
Expand All @@ -1582,7 +1615,8 @@ public static function require_javascript($file) {
* @see http://www.w3.org/TR/REC-CSS2/media.html
*/
public static function require_css($file, $media = null) {
self::$extra_requirements['css'][] = array($file, $media);
Deprecation::notice('3.2', 'Use "LeftAndMain.extra_requirements_css" config setting instead');
Config::inst()->update('LeftAndMain', 'extra_requirements_css', array($file => array('media' => $media)));
}

/**
Expand All @@ -1594,7 +1628,8 @@ public static function require_css($file, $media = null) {
* @param $media String Comma-separated list of media-types (e.g. "screen,projector")
*/
public static function require_themed_css($name, $media = null) {
self::$extra_requirements['themedcss'][] = array($name, $media);
Deprecation::notice('3.2', 'Use "LeftAndMain.extra_requirements_css" config setting instead');
Config::inst()->update('LeftAndMain', 'extra_requirements_css', array($name => array('media' => $media)));
}

}
Expand Down

0 comments on commit 3334eaf

Please sign in to comment.