1 config.admin.inc config_diff($name)

Return a formatted diff of a named config between staging and active.

Parameters

string $name: The name of the configuration object to diff.

Return value

array: An array of formatted strings showing the diffs between the two storages.

See also

config_diff_page()

File

core/modules/config/config.admin.inc, line 562
Admin page callbacks for the Configuration Management module.

Code

function config_diff($name) {
  $active_storage = config_get_config_storage('active');
  $staging_storage = config_get_config_storage('staging');

  $source_data = explode("\n", backdrop_json_encode($active_storage->read($name), TRUE));
  $target_data = explode("\n", backdrop_json_encode($staging_storage->read($name), TRUE));

  // Check for new or removed files.
  if ($source_data === array('false')) {
    // Added file.
    $source_data = array(t('File added'));
  }
  if ($target_data === array('false')) {
    // Deleted file.
    $target_data = array(t('File removed'));
  }

  $diff = new Diff($source_data, $target_data);
  $formatter = new BackdropDiffFormatter();
  return $formatter->format($diff);
}