Commit 5bb0d5e6 authored by webchick's avatar webchick

Issue #2053489 by chx, tim.plunkett: Standardize on \Drupal throughout core.

parent 1024ba83
......@@ -74,7 +74,7 @@ function authorize_access_allowed() {
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES);
$request = Request::createFromGlobals();
Drupal::getContainer()->set('request', $request);
\Drupal::getContainer()->set('request', $request);
// This must go after drupal_bootstrap(), which unsets globals!
global $conf;
......@@ -83,9 +83,9 @@ function authorize_access_allowed() {
// display errors via the maintenance theme.
$module_list['system'] = 'core/modules/system/system.module';
$module_list['user'] = 'core/modules/user/user.module';
Drupal::moduleHandler()->setModuleList($module_list);
Drupal::moduleHandler()->load('system');
Drupal::moduleHandler()->load('user');
\Drupal::moduleHandler()->setModuleList($module_list);
\Drupal::moduleHandler()->load('system');
\Drupal::moduleHandler()->load('user');
// Initialize the language system.
drupal_language_initialize();
......
......@@ -332,7 +332,7 @@ function ajax_base_page_theme() {
// to see the default theme, token validation isn't required for that, and
// bypassing it allows most use-cases to work even when accessed from the
// page cache.
if ($theme === Drupal::config('system.theme')->get('default') || drupal_valid_token($token, $theme)) {
if ($theme === \Drupal::config('system.theme')->get('default') || drupal_valid_token($token, $theme)) {
return $theme;
}
}
......@@ -368,7 +368,7 @@ function ajax_prepare_response($page_callback_result) {
break;
case MENU_SITE_OFFLINE:
$commands[] = ajax_command_alert(filter_xss_admin(t(Drupal::config('system.maintenance')->get('message'), array('@site' => Drupal::config('system.site')->get('name')))));
$commands[] = ajax_command_alert(filter_xss_admin(t(\Drupal::config('system.maintenance')->get('message'), array('@site' => \Drupal::config('system.site')->get('name')))));
break;
}
}
......
......@@ -27,7 +27,7 @@ function authorize_filetransfer_form($form, &$form_state) {
}
$available_backends = $_SESSION['authorize_filetransfer_info'];
if (!Drupal::request()->isSecure()) {
if (!\Drupal::request()->isSecure()) {
$form['information']['https_warning'] = array(
'#prefix' => '<div class="messages messages--error">',
'#markup' => t('WARNING: You are not using an encrypted connection, so your password will be sent in plain text. <a href="@https-link">Learn more</a>.', array('@https-link' => 'http://drupal.org/https-information')),
......@@ -39,7 +39,7 @@ function authorize_filetransfer_form($form, &$form_state) {
if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default'])) {
$authorize_filetransfer_default = $form_state['values']['connection_settings']['authorize_filetransfer_default'];
}
elseif ($authorize_filetransfer_default = Drupal::config('system.authorize')->get('filetransfer_default'));
elseif ($authorize_filetransfer_default = \Drupal::config('system.authorize')->get('filetransfer_default'));
else {
$authorize_filetransfer_default = key($available_backends);
}
......@@ -138,7 +138,7 @@ function authorize_filetransfer_form($form, &$form_state) {
* @see hook_filetransfer_backends()
*/
function _authorize_filetransfer_connection_settings($backend) {
$auth_connection_config = Drupal::config('system.authorize')->get('filetransfer_connection_settings_' . $backend);
$auth_connection_config = \Drupal::config('system.authorize')->get('filetransfer_connection_settings_' . $backend);
$defaults = $auth_connection_config ? $auth_connection_config : array();
$form = array();
......@@ -253,9 +253,9 @@ function authorize_filetransfer_form_submit($form, &$form_state) {
}
}
// Set this one as the default authorize method.
Drupal::config('system.authorize')->set('filetransfer_default', $filetransfer_backend);
\Drupal::config('system.authorize')->set('filetransfer_default', $filetransfer_backend);
// Save the connection settings minus the password.
Drupal::config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
\Drupal::config('system.authorize')->set('filetransfer_connection_settings_' . $filetransfer_backend, $connection_settings);
$filetransfer = authorize_get_filetransfer($filetransfer_backend, $form_state['values']['connection_settings'][$filetransfer_backend]);
......
......@@ -36,7 +36,7 @@ function _batch_page(Request $request) {
// Retrieve the current state of the batch.
if (!$batch) {
$batch = Drupal::service('batch.storage')->load($request_id);
$batch = \Drupal::service('batch.storage')->load($request_id);
if (!$batch) {
drupal_set_message(t('No active batch.'), 'error');
return new RedirectResponse(url('<front>', array('absolute' => TRUE)));
......@@ -394,7 +394,7 @@ function _batch_finished() {
// Clean up the batch table and unset the static $batch variable.
if ($batch['progressive']) {
Drupal::service('batch.storage')->delete($batch['id']);
\Drupal::service('batch.storage')->delete($batch['id']);
foreach ($batch['sets'] as $batch_set) {
if ($queue = _batch_queue($batch_set)) {
$queue->deleteQueue();
......@@ -415,7 +415,7 @@ function _batch_finished() {
if ($_batch['progressive']) {
// Revert the 'destination' that was saved in batch_process().
if (isset($_batch['destination'])) {
Drupal::request()->query->set('destination', $_batch['destination']);
\Drupal::request()->query->set('destination', $_batch['destination']);
}
// Determine the target path to redirect to.
......@@ -463,6 +463,6 @@ function _batch_finished() {
*/
function _batch_shutdown() {
if ($batch = batch_get()) {
Drupal::service('batch.storage')->update($batch);
\Drupal::service('batch.storage')->update($batch);
}
}
......@@ -451,7 +451,7 @@ function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) {
* return the expected values.
*
* Most other parameters do not need to be passed in, but may be necessary in
* some cases; for example, if Drupal::request()->getClientIP()
* some cases; for example, if \Drupal::request()->getClientIP()
* needs to return anything but the standard localhost value ('127.0.0.1'),
* the command line script should pass in the desired value via the
* 'REMOTE_ADDR' key.
......@@ -744,17 +744,17 @@ function drupal_get_filename($type, $name, $filename = NULL) {
// Verify that we have an keyvalue service before using it. This is required
// because this function is called during installation.
// @todo Inject database connection into KeyValueStore\DatabaseStorage.
if (($container = Drupal::getContainer()) && $container->has('keyvalue') && function_exists('db_query')) {
if (($container = \Drupal::getContainer()) && $container->has('keyvalue') && function_exists('db_query')) {
if ($type == 'module') {
if (empty($files[$type])) {
$files[$type] = Drupal::moduleHandler()->getModuleList();
$files[$type] = \Drupal::moduleHandler()->getModuleList();
}
if (isset($files[$type][$name])) {
return $files[$type][$name];
}
}
try {
$file_list = Drupal::state()->get('system.' . $type . '.files');
$file_list = \Drupal::state()->get('system.' . $type . '.files');
if ($file_list && isset($file_list[$name]) && file_exists(DRUPAL_ROOT . '/' . $file_list[$name])) {
$files[$type][$name] = $file_list[$name];
}
......@@ -839,7 +839,7 @@ function variable_initialize($conf = array()) {
else {
// Cache miss. Avoid a stampede.
$name = 'variable_init';
$lock = Drupal::lock();
$lock = \Drupal::lock();
if (!$lock->acquire($name, 1)) {
// Another request is building the variable cache.
// Wait, then re-run this function.
......@@ -953,7 +953,7 @@ function variable_del($name) {
function drupal_page_cache_get_cid(Request $request) {
$cid_parts = array(
$request->getUri(),
Drupal::service('content_negotiation')->getContentType($request),
\Drupal::service('content_negotiation')->getContentType($request),
);
return sha1(implode(':', $cid_parts));
}
......@@ -974,7 +974,7 @@ function drupal_page_cache_get_cid(Request $request) {
*/
function drupal_page_get_cache(Request $request) {
if (drupal_page_is_cacheable()) {
return Drupal::cache('page')->get(drupal_page_cache_get_cid($request));
return \Drupal::cache('page')->get(drupal_page_cache_get_cid($request));
}
}
......@@ -1011,8 +1011,8 @@ function drupal_page_is_cacheable($allow_caching = NULL) {
* TRUE if the item is loaded or has already been loaded.
*/
function drupal_load($type, $name) {
if ($type == 'module' && Drupal::moduleHandler()->moduleExists($name)) {
return Drupal::moduleHandler()->load($name);
if ($type == 'module' && \Drupal::moduleHandler()->moduleExists($name)) {
return \Drupal::moduleHandler()->load($name);
}
// Once a file is included this can't be reversed during a request so do not
......@@ -1211,7 +1211,7 @@ function drupal_page_header() {
* response is sent.
*/
function drupal_serve_page_from_cache(stdClass $cache, Response $response, Request $request) {
$config = Drupal::config('system.performance');
$config = \Drupal::config('system.performance');
// First half: we must determine if we should be returning a 304.
......@@ -1354,7 +1354,7 @@ function drupal_serve_page_from_cache(stdClass $cache, Response $response, Reque
* @ingroup sanitization
*/
function t($string, array $args = array(), array $options = array()) {
return Drupal::translation()->translate($string, $args, $options);
return \Drupal::translation()->translate($string, $args, $options);
}
/**
......@@ -1542,7 +1542,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG
);
try {
$request = Drupal::request();
$request = \Drupal::request();
$log_entry['request_uri'] = $request->getUri();
$log_entry['referer'] = $request->headers->get('Referer', '');
$log_entry['ip'] = $request->getClientIP();
......@@ -1552,7 +1552,7 @@ function watchdog($type, $message, array $variables = NULL, $severity = WATCHDOG
}
// Call the logging hooks to log/process the message
foreach (Drupal::moduleHandler()->getImplementations('watchdog') as $module) {
foreach (\Drupal::moduleHandler()->getImplementations('watchdog') as $module) {
$function = $module . '_watchdog';
$function($log_entry);
}
......@@ -1714,7 +1714,7 @@ function drupal_set_title($title = NULL, $output = Title::CHECK_PLAIN) {
function drupal_anonymous_user() {
$values = array(
'uid' => 0,
'hostname' => Drupal::request()->getClientIP(),
'hostname' => \Drupal::request()->getClientIP(),
'roles' => array(DRUPAL_ANONYMOUS_RID),
);
return new UserSession($values);
......@@ -1869,7 +1869,7 @@ function drupal_handle_request($test_only = FALSE) {
*/
function drupal_get_user_timezone() {
global $user;
$config = Drupal::config('system.date');
$config = \Drupal::config('system.date');
if ($user && $config->get('timezone.user.configurable') && $user->isAuthenticated() && $user->getTimezone()) {
return $user->getTimezone();
......@@ -1966,7 +1966,7 @@ function _drupal_bootstrap_configuration() {
// Load the procedural configuration system helper functions.
require_once __DIR__ . '/config.inc';
// Set the Drupal custom error handler. (requires Drupal::config())
// Set the Drupal custom error handler. (requires \Drupal::config())
set_error_handler('_drupal_error_handler');
set_exception_handler('_drupal_exception_handler');
......@@ -1985,7 +1985,7 @@ function _drupal_bootstrap_configuration() {
function _drupal_bootstrap_kernel() {
// Normally, index.php puts a container in the Drupal class by creating a
// kernel. If there is no container yet, create one.
if (!Drupal::getContainer()) {
if (!\Drupal::getContainer()) {
$kernel = new DrupalKernel('prod', drupal_classloader());
$kernel->boot();
}
......@@ -2004,7 +2004,7 @@ function _drupal_bootstrap_page_cache() {
}
else {
drupal_bootstrap(DRUPAL_BOOTSTRAP_VARIABLES, FALSE);
$config = Drupal::config('system.performance');
$config = \Drupal::config('system.performance');
$cache_enabled = $config->get('cache.page.use_internal');
}
......@@ -2112,19 +2112,19 @@ function drupal_get_bootstrap_phase() {
* object instances or FALSE if none exist yet.
*/
function drupal_container() {
return Drupal::getContainer();
return \Drupal::getContainer();
}
/**
* Returns the list of enabled modules.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->getModuleList().
* \Drupal::moduleHandler()->getModuleList().
*
* @see \Drupal\Core\Extension\ModuleHandler::getModuleList()
*/
function module_list() {
$modules = array_keys(Drupal::moduleHandler()->getModuleList());
$modules = array_keys(\Drupal::moduleHandler()->getModuleList());
return array_combine($modules, $modules);
}
......@@ -2132,12 +2132,12 @@ function module_list() {
* Determines which modules are implementing a hook.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->getImplementations($hook).
* \Drupal::moduleHandler()->getImplementations($hook).
*
* @see \Drupal\Core\Extension\ModuleHandler::getImplementations()
*/
function module_implements($hook) {
return Drupal::moduleHandler()->getImplementations($hook);
return \Drupal::moduleHandler()->getImplementations($hook);
}
/**
......@@ -2147,7 +2147,7 @@ function module_implements($hook) {
* arguments by reference.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->invoke($module, $hook, $args = array()).
* \Drupal::moduleHandler()->invoke($module, $hook, $args = array()).
*
* @see drupal_alter()
* @see \Drupal\Core\Extension\ModuleHandler::invoke()
......@@ -2156,7 +2156,7 @@ function module_invoke($module, $hook) {
$args = func_get_args();
// Remove $module and $hook from the arguments.
unset($args[0], $args[1]);
return Drupal::moduleHandler()->invoke($module, $hook, $args);
return \Drupal::moduleHandler()->invoke($module, $hook, $args);
}
/**
......@@ -2166,7 +2166,7 @@ function module_invoke($module, $hook) {
* arguments by reference.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->invokeAll($hook).
* \Drupal::moduleHandler()->invokeAll($hook).
*
* @see drupal_alter()
* @see \Drupal\Core\Extension\ModuleHandler::invokeAll()
......@@ -2175,43 +2175,43 @@ function module_invoke_all($hook) {
$args = func_get_args();
// Remove $hook from the arguments.
array_shift($args);
return Drupal::moduleHandler()->invokeAll($hook, $args);
return \Drupal::moduleHandler()->invokeAll($hook, $args);
}
/**
* Passes alterable variables to specific hook_TYPE_alter() implementations.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->alter($hook).
* \Drupal::moduleHandler()->alter($hook).
*
* @see \Drupal\Core\Extension\ModuleHandler::alter()
*/
function drupal_alter($type, &$data, &$context1 = NULL, &$context2 = NULL) {
return Drupal::moduleHandler()->alter($type, $data, $context1, $context2);
return \Drupal::moduleHandler()->alter($type, $data, $context1, $context2);
}
/**
* Determines whether a given module exists.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->moduleExists($module).
* \Drupal::moduleHandler()->moduleExists($module).
*
* @see \Drupal\Core\Extension\ModuleHandler::moduleExists()
*/
function module_exists($module) {
return Drupal::moduleHandler()->moduleExists($module);
return \Drupal::moduleHandler()->moduleExists($module);
}
/**
* Determines whether a module implements a hook.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::moduleHandler()->implementsHook($module, $hook).
* \Drupal::moduleHandler()->implementsHook($module, $hook).
*
* @see \Drupal\Core\Extension\ModuleHandler::implementsHook()
*/
function module_hook($module, $hook) {
return Drupal::moduleHandler()->implementsHook($module, $hook);
return \Drupal::moduleHandler()->implementsHook($module, $hook);
}
/**
......@@ -2345,9 +2345,9 @@ function drupal_installation_attempted() {
* Initializes all the defined language types and sets the default langcode.
*/
function drupal_language_initialize() {
$language_manager = Drupal::languageManager();
$language_manager = \Drupal::languageManager();
$language_manager->init();
Drupal::translation()->setDefaultLangcode($language_manager->getLanguage(Language::TYPE_INTERFACE)->id);
\Drupal::translation()->setDefaultLangcode($language_manager->getLanguage(Language::TYPE_INTERFACE)->id);
}
/**
......@@ -2359,10 +2359,10 @@ function drupal_language_initialize() {
* The type of language object needed, e.g. Language::TYPE_INTERFACE.
*
* @deprecated as of Drupal 8.0. Use
* Drupal::languageManager()->getLanguage($type).
* \Drupal::languageManager()->getLanguage($type).
*/
function language($type) {
return Drupal::languageManager()->getLanguage($type);
return \Drupal::languageManager()->getLanguage($type);
}
/**
......@@ -2373,7 +2373,7 @@ function language($type) {
* name and its value is its configurability (TRUE/FALSE).
*/
function language_types_get_all() {
$types = Drupal::config('system.language.types')->get('all');
$types = \Drupal::config('system.language.types')->get('all');
return $types ? $types : array_keys(language_types_get_default());
}
......@@ -2399,7 +2399,7 @@ function language_types_get_default() {
* TRUE if more than one language is enabled.
*/
function language_multilingual() {
return Drupal::languageManager()->isMultilingual();
return \Drupal::languageManager()->isMultilingual();
}
/**
......@@ -2433,7 +2433,7 @@ function language_list($flags = Language::STATE_CONFIGURABLE) {
// save the same object without data loss.
foreach ($language_entities as $langcode_config_name) {
$langcode = substr($langcode_config_name, strlen('language.entity.'));
$info = Drupal::config($langcode_config_name)->get();
$info = \Drupal::config($langcode_config_name)->get();
$languages[$langcode] = new Language(array(
'default' => ($info['id'] == $default->id),
'name' => $info['label'],
......@@ -3083,13 +3083,13 @@ function drupal_check_memory_limit($required, $memory_limit = NULL) {
/**
* Get locking layer instance.
*
* @deprecated Use Drupal::lock() instead, or even better have the lock service
* @deprecated Use \Drupal::lock() instead, or even better have the lock service
* injected into your object.
*
* @return Drupal\Core\Lock\LockBackendInterface
*/
function lock() {
return Drupal::lock();
return \Drupal::lock();
}
/**
......
......@@ -26,7 +26,7 @@
* @see Drupal\Core\Cache\CacheBackendInterface
*/
function cache($bin = 'cache') {
return Drupal::cache($bin);
return \Drupal::cache($bin);
}
/**
......
......@@ -361,7 +361,7 @@ function _drupal_default_html_head() {
);
// Show Drupal and the major version number in the META GENERATOR tag.
// Get the major version.
list($version, ) = explode('.', Drupal::VERSION);
list($version, ) = explode('.', \Drupal::VERSION);
$elements['system_meta_generator'] = array(
'#type' => 'html_tag',
'#tag' => 'meta',
......@@ -447,7 +447,7 @@ function drupal_get_feeds($delimiter = "\n") {
*/
function drupal_get_query_parameters(array $query = NULL, array $exclude = array(), $parent = '') {
if (!isset($query)) {
$query = Drupal::request()->query->all();
$query = \Drupal::request()->query->all();
}
return Url::filterQueryParameters($query, $exclude, $parent);
}
......@@ -487,7 +487,7 @@ function drupal_get_destination() {
return $destination;
}
$query = Drupal::request()->query;
$query = \Drupal::request()->query;
if ($query->has('destination')) {
$destination = array('destination' => $query->get('destination'));
}
......@@ -1110,7 +1110,7 @@ function format_interval($interval, $granularity = 2, $langcode = NULL) {
* @see \Drupal\Component\Datetime\Date::format()
*/
function format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
return Drupal::service('date')->format($timestamp, $type, $format, $timezone, $langcode);
return \Drupal::service('date')->format($timestamp, $type, $format, $timezone, $langcode);
}
/**
......@@ -1201,7 +1201,7 @@ function datetime_default_format_type() {
* @see \Drupal\Core\Routing\UrlGeneratorInterface::generateFromPath().
*/
function url($path = NULL, array $options = array()) {
$generator = Drupal::urlGenerator();
$generator = \Drupal::urlGenerator();
try {
$url = $generator->generateFromPath($path, $options);
}
......@@ -1345,7 +1345,7 @@ function l($text, $path, array $options = array()) {
'path' => current_path(),
'front_page' => drupal_is_front_page(),
'language' => language(Language::TYPE_URL)->id,
'query' => Drupal::service('request')->query->all(),
'query' => \Drupal::service('request')->query->all(),
);
}
......@@ -1371,7 +1371,7 @@ function l($text, $path, array $options = array()) {
}
// Allow other modules to modify the structure of the link.
Drupal::moduleHandler()->alter('link', $variables);
\Drupal::moduleHandler()->alter('link', $variables);
// Move attributes out of options. url() doesn't need them.
$attributes = new Attribute($variables['options']['attributes']);
......@@ -1861,7 +1861,7 @@ function drupal_pre_render_styles($elements) {
$css_assets = $elements['#items'];
// Aggregate the CSS if necessary, but only during normal site operation.
if (!defined('MAINTENANCE_MODE') && Drupal::config('system.performance')->get('css.preprocess')) {
if (!defined('MAINTENANCE_MODE') && \Drupal::config('system.performance')->get('css.preprocess')) {
$css_assets = \Drupal::service('asset.css.collection_optimizer')->optimize($css_assets);
}
return \Drupal::service('asset.css.collection_renderer')->render($css_assets);
......@@ -1871,7 +1871,7 @@ function drupal_pre_render_styles($elements) {
* Deletes old cached CSS files.
*/
function drupal_clear_css_cache() {
Drupal::state()->delete('drupal_css_cache_files');
\Drupal::state()->delete('drupal_css_cache_files');
file_scan_directory('public://css', '/.*/', array('callback' => 'drupal_delete_file_if_stale'));
}
......@@ -1884,7 +1884,7 @@ function drupal_clear_css_cache() {
*/
function drupal_delete_file_if_stale($uri) {
// Default stale file threshold is 30 days.
if (REQUEST_TIME - filemtime($uri) > Drupal::config('system.performance')->get('stale_file_threshold')) {
if (REQUEST_TIME - filemtime($uri) > \Drupal::config('system.performance')->get('stale_file_threshold')) {
file_unmanaged_delete($uri);
}
}
......@@ -2488,7 +2488,7 @@ function drupal_pre_render_scripts($elements) {
// Aggregate the JavaScript if necessary, but only during normal site
// operation.