function ConfigManager::diff
Same name in other branches
- 9 core/lib/Drupal/Core/Config/ConfigManager.php \Drupal\Core\Config\ConfigManager::diff()
- 10 core/lib/Drupal/Core/Config/ConfigManager.php \Drupal\Core\Config\ConfigManager::diff()
- 11.x core/lib/Drupal/Core/Config/ConfigManager.php \Drupal\Core\Config\ConfigManager::diff()
Overrides ConfigManagerInterface::diff
File
-
core/
lib/ Drupal/ Core/ Config/ ConfigManager.php, line 176
Class
- ConfigManager
- The ConfigManager provides helper functions for the configuration system.
Namespace
Drupal\Core\ConfigCode
public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $source_name, $target_name = NULL, $collection = StorageInterface::DEFAULT_COLLECTION) {
if ($collection != StorageInterface::DEFAULT_COLLECTION) {
$source_storage = $source_storage->createCollection($collection);
$target_storage = $target_storage->createCollection($collection);
}
if (!isset($target_name)) {
$target_name = $source_name;
}
// The output should show configuration object differences formatted as YAML.
// But the configuration is not necessarily stored in files. Therefore, they
// need to be read and parsed, and lastly, dumped into YAML strings.
$source_data = explode("\n", Yaml::encode($source_storage->read($source_name)));
$target_data = explode("\n", Yaml::encode($target_storage->read($target_name)));
// Check for new or removed files.
if ($source_data === [
'false',
]) {
// Added file.
// Cast the result of t() to a string, as the diff engine doesn't know
// about objects.
$source_data = [
(string) $this->t('File added'),
];
}
if ($target_data === [
'false',
]) {
// Deleted file.
// Cast the result of t() to a string, as the diff engine doesn't know
// about objects.
$target_data = [
(string) $this->t('File removed'),
];
}
return new Diff($source_data, $target_data);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.