function ConfigController::diff

Same name in other branches
  1. 9 core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::diff()
  2. 8.9.x core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::diff()
  3. 11.x core/modules/config/src/Controller/ConfigController.php \Drupal\config\Controller\ConfigController::diff()

Shows diff of specified configuration file.

Parameters

string $source_name: The name of the configuration file.

string $target_name: (optional) The name of the target configuration file if different from the $source_name.

string $collection: (optional) The configuration collection name. Defaults to the default collection.

Return value

array Table showing a two-way diff between the active and staged configuration.

1 string reference to 'ConfigController::diff'
config.routing.yml in core/modules/config/config.routing.yml
core/modules/config/config.routing.yml

File

core/modules/config/src/Controller/ConfigController.php, line 173

Class

ConfigController
Returns responses for config module routes.

Namespace

Drupal\config\Controller

Code

public function diff($source_name, $target_name = NULL, $collection = NULL) {
    if (!isset($collection)) {
        $collection = StorageInterface::DEFAULT_COLLECTION;
    }
    $syncStorage = $this->importTransformer
        ->transform($this->syncStorage);
    $diff = $this->configManager
        ->diff($this->targetStorage, $syncStorage, $source_name, $target_name, $collection);
    $this->diffFormatter->show_header = FALSE;
    $build = [];
    $build['#title'] = $this->t('View changes of @config_file', [
        '@config_file' => $source_name,
    ]);
    // Add the CSS for the inline diff.
    $build['#attached']['library'][] = 'system/diff';
    $build['diff'] = [
        '#type' => 'table',
        '#attributes' => [
            'class' => [
                'diff',
            ],
        ],
        '#header' => [
            [
                'data' => $this->t('Active'),
                'colspan' => '2',
            ],
            [
                'data' => $this->t('Staged'),
                'colspan' => '2',
            ],
        ],
        '#rows' => $this->diffFormatter
            ->format($diff),
    ];
    $build['back'] = [
        '#type' => 'link',
        '#attributes' => [
            'class' => [
                'dialog-cancel',
            ],
        ],
        '#title' => "Back to 'Synchronize configuration' page.",
        '#url' => Url::fromRoute('config.sync'),
    ];
    return $build;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.