public function ConfigFactory::rename

Renames a configuration object using the storage controller.

Parameters

string $old_name: The old name of the configuration object.

string $new_name: The new name of the configuration object.

Return value

\Drupal\Core\Config\Config The renamed config object.

File

drupal/core/lib/Drupal/Core/Config/ConfigFactory.php, line 121
Definition of Drupal\Core\Config\ConfigFactory.

Class

ConfigFactory
Defines the configuration object factory.

Namespace

Drupal\Core\Config

Code

public function rename($old_name, $new_name) {
  $context = $this
    ->getContext();
  $old_cache_key = $this
    ->getCacheKey($old_name, $context);
  $new_cache_key = $this
    ->getCacheKey($new_name, $context);
  if (isset($this->cache[$old_cache_key])) {
    $config = $this->cache[$old_cache_key];
    unset($this->cache[$old_cache_key]);
  }
  else {

    // Create the config object if it's not yet loaded into the static cache.
    $config = new Config($old_name, $this->storage, $context);
  }
  $this->cache[$new_cache_key] = $config;
  $this->storage
    ->rename($old_name, $new_name);
  return $this->cache[$new_cache_key]
    ->setName($new_name)
    ->init();
}