function config_diff

Return a formatted diff of a named config between two storages.

@todo Make renderer injectable

Parameters

Drupal\Core\Config\StorageInterface $source_storage: The storage to diff configuration from.

Drupal\Core\Config\StorageInterface $target_storage: The storage to diff configuration to.

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

Return value

core/lib/Drupal/Component/Diff A formatted string showing the difference between the two storages.

2 calls to config_diff()
ConfigController::diff in drupal/core/modules/config/lib/Drupal/config/Controller/ConfigController.php
Shows diff of specificed configuration file.
ConfigDiffTest::testDiff in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigDiffTest.php
Tests calculating the difference between two sets of configuration.
1 string reference to 'config_diff'
config_menu in drupal/core/modules/config/config.module
Implements hook_menu().

File

drupal/core/includes/config.inc, line 214
This is the API for configuration storage.

Code

function config_diff(StorageInterface $source_storage, StorageInterface $target_storage, $name) {
  require_once DRUPAL_ROOT . '/core/lib/Drupal/Component/Diff/DiffEngine.php';

  // 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.
  $dumper = new Dumper();
  $dumper
    ->setIndentation(2);
  $source_data = explode("\n", $dumper
    ->dump($source_storage
    ->read($name), PHP_INT_MAX));
  $target_data = explode("\n", $dumper
    ->dump($target_storage
    ->read($name), PHP_INT_MAX));

  // 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'),
    );
  }
  return new Diff($source_data, $target_data);
}