diff --git a/core/includes/config.inc b/core/includes/config.inc index e704d04..95d4d83 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -77,17 +77,16 @@ function config_get_storage_names_with_prefix($prefix = '') { * 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. - * @param $class - * The class name of the config object to be returned. Defaults to - * ConfigObject. + * @param string $class + * (optional) The name of the class to use for the configuration object. * * @return * An instance of the class specified in the $class parameter. * * @todo Replace with DI container. */ -function config($name, $class = 'Drupal\Core\Config\ConfigObject') { +function config($name, $class = NULL) { // @todo Do not reload an already loaded config object. // @todo Make it possible to skip load for known to be new config objects? - return ConfigFactory::get($name, $class)->load(); + return ConfigFactory::get($name, $class); } diff --git a/core/lib/Drupal/Core/Config/ConfigFactory.php b/core/lib/Drupal/Core/Config/ConfigFactory.php index 29e9604..1004fdd 100644 --- a/core/lib/Drupal/Core/Config/ConfigFactory.php +++ b/core/lib/Drupal/Core/Config/ConfigFactory.php @@ -1,5 +1,10 @@ selectStorage('read', $name); + $data = $storage->read($name); + if (!empty($data['config_class'])) { + $class = $data['config_class']; + } + else { + $class = 'Drupal\Core\Config\ConfigObject'; + } + } + self::$configObjects[$manager_class][$name] = new $class($name, self::$storageManagers[$manager_class]); + + // If we loaded data already, set it. + if (isset($data)) { + self::$configObjects[$manager_class][$name]->setData($data !== FALSE ? $data : array()); + } + // Otherwise, load it. + else { + self::$configObjects[$manager_class][$name]->load(); + } } return self::$configObjects[$manager_class][$name]; }