diff --git a/core/includes/install.inc b/core/includes/install.inc index 3fdc48c..fa70bcd 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -623,10 +623,7 @@ function drupal_install_system() { require_once DRUPAL_ROOT . '/' . $system_path . '/system.install'; $system_versions = drupal_get_schema_versions('system'); $system_version = $system_versions ? max($system_versions) : SCHEMA_INSTALLED; - drupal_container() - ->get('keyvalue') - ->get('system.schema') - ->set('system', $system_version); + Drupal::keyValue('system.schema')->set('system', $system_version); // System module needs to be enabled and the system/module lists need to be // reset first in order to allow config_install_default_config() to invoke diff --git a/core/includes/module.inc b/core/includes/module.inc index 99eac78..d675cd2 100644 --- a/core/includes/module.inc +++ b/core/includes/module.inc @@ -284,7 +284,7 @@ function module_enable($module_list, $enable_dependencies = TRUE) { $modules_installed = array(); $modules_enabled = array(); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $module_config = config('system.module'); $disabled_config = config('system.module.disabled'); $module_handler = drupal_container()->get('module_handler'); @@ -567,7 +567,7 @@ function module_uninstall($module_list = array(), $uninstall_dependents = TRUE) } $storage = drupal_container()->get('config.storage'); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $disabled_config = config('system.module.disabled'); foreach ($module_list as $module) { // Uninstall the module. diff --git a/core/includes/schema.inc b/core/includes/schema.inc index e599923..24df9d4 100644 --- a/core/includes/schema.inc +++ b/core/includes/schema.inc @@ -173,7 +173,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F } if (!$versions) { - if (!$versions = drupal_container()->get('keyvalue')->get('system.schema')->getAll()) { + if (!$versions = Drupal::keyValue('system.schema')->getAll()) { $versions = array(); } } @@ -195,7 +195,7 @@ function drupal_get_installed_schema_version($module, $reset = FALSE, $array = F * The new schema version. */ function drupal_set_installed_schema_version($module, $version) { - drupal_container()->get('keyvalue')->get('system.schema')->set($module, $version); + Drupal::keyValue('system.schema')->set($module, $version); // Reset the static cache of module schema versions. drupal_get_installed_schema_version(NULL, TRUE); } diff --git a/core/includes/update.inc b/core/includes/update.inc index bf11562..9c6bb2c 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -343,7 +343,7 @@ function update_prepare_d8_bootstrap() { $disabled_modules = config('system.module.disabled'); $theme_config = config('system.theme'); $disabled_themes = config('system.theme.disabled'); - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); // Load system.module, because update_prepare_d8_bootstrap() is called in // the initial minimal update.php bootstrap that performs the core @@ -663,7 +663,7 @@ function update_fix_d8_requirements() { * if the module was not installed before. */ function update_module_enable(array $modules, $schema_version = 0) { - $schema_store = drupal_container()->get('keyvalue')->get('system.schema'); + $schema_store = Drupal::keyValue('system.schema'); $old_schema = array(); foreach ($modules as $module) { // Check for initial schema and install it. The schema version of a newly @@ -1237,7 +1237,7 @@ function update_retrieve_dependencies() { $return = array(); // Get a list of installed modules, arranged so that we invoke their hooks in // the same order that module_invoke_all() does. - foreach (drupal_container()->get('keyvalue')->get('system.schema')->getAll() as $module => $schema) { + foreach (Drupal::keyValue('system.schema')->getAll() as $module => $schema) { if ($schema == SCHEMA_UNINSTALLED) { // Nothing to upgrade. continue; diff --git a/core/lib/Drupal.php b/core/lib/Drupal.php index 5b0b502..da67581 100644 --- a/core/lib/Drupal.php +++ b/core/lib/Drupal.php @@ -140,4 +140,121 @@ public static function lock() { return static::$container->get('lock'); } + /** + * Retrieves a configuration object. + * + * This is the main entry point to the configuration API. Calling + * @code config('book.admin') @endcode will return a configuration object in + * which the book module can store its administrative settings. + * + * @param string $name + * The name of the configuration object to retrieve. The name corresponds to + * a configuration file. For @code config('book.admin') @endcode, the config + * object returned will contain the contents of book.admin configuration file. + * + * @return Drupal\Core\Config\Config + * A configuration object. + */ + public static function config($name) { + return static::$container->get('config.factory')->get($name); + } + + /** + * Instantiates and statically caches the correct class for a queue. + * + * The following variables can be set by variable_set or $conf overrides: + * - queue_class_$name: The class to be used for the queue $name. + * - queue_default_class: The class to use when queue_class_$name is not + * defined. Defaults to Drupal\Core\Queue\System, a reliable backend using + * SQL. + * - queue_default_reliable_class: The class to use when queue_class_$name is + * not defined and the queue_default_class is not reliable. Defaults to + * Drupal\Core\Queue\System. + * + * @param string $name + * The name of the queue to work with. + * @param bool $reliable + * (optional) TRUE if the ordering of items and guaranteeing every item + * executes at least once is important, FALSE if scalability is the main + * concern. Defaults to FALSE. + * + * @return Drupal\Core\Queue\QueueInterface + * The queue object for a given name. + */ + public static function queue($name, $reliable = FALSE) { + return static::$container->get('queue')->get($name, $reliable); + } + + /** + * Returns a key/value storage collection. + * + * @param $collection + * Name of the key/value collection to return. + * + * @return \Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + public static function keyValue($collection) { + return static::$container->get('keyvalue')->get($collection); + } + + /** + * Returns the state storage service. + * + * Use this to store machine-generated data, local to a specific environment + * that does not need deploying and does not need human editing; for example, + * the last time cron was run. Data which needs to be edited by humans and + * needs to be the same across development, production, etc. environments + * (for example, the system maintenance message) should use config() instead. + * + * @return Drupal\Core\KeyValueStore\KeyValueStoreInterface + */ + public static function state() { + return static::$container->get('state'); + } + + /** + * Returns the default http client. + * + * @return Guzzle\Http\ClientInterface + * A guzzle http client instance. + */ + public static function httpClient() { + return static::$container->get('http_default_client'); + } + + /** + * Returns the entity query object for this entity type. + * + * @param string $entity_type + * The entity type, e.g. node, for which the query object should be + * returned. + * @param string $conjunction + * AND if all conditions in the query need to apply, OR if any of them is + * enough. Optional, defaults to AND. + * + * @return \Drupal\Core\Entity\Query\QueryInterface + * The query object that can query the given entity type. + */ + public static function entityQuery($entity_type, $conjunction = 'AND') { + return static::$container->get('entity.query')->get($entity_type, $conjunction); + } + + /** + * Returns the flood instance. + * + * @return \Drupal\Core\Flood\FloodInterface + */ + public static function flood() { + return static::$container->get('flood'); + } + + /** + * Returns the module handler. + * + * @return \Drupal\Core\Extension\ModuleHandler + */ + public static function moduleHandler() { + return static::$container->get('module_handler'); + } + }