class ConfigController

Returns responses for config module routes.

Hierarchy

Expanded class hierarchy of ConfigController

File

drupal/core/modules/config/lib/Drupal/config/Controller/ConfigController.php, line 20
Contains \Drupal\config\Controller\ConfigController

Namespace

Drupal\config\Controller
View source
class ConfigController implements ControllerInterface {

  /**
   * The target storage.
   *
   * @var \Drupal\Core\Config\StorageInterface;
   */
  protected $targetStorage;

  /**
   * The source storage.
   *
   * @var \Drupal\Core\Config\StorageInterface;
   */
  protected $sourceStorage;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.storage'), $container
      ->get('config.storage.staging'));
  }

  /**
   * Constructs a ConfigController object.
   *
   * @param \Drupal\Core\Config\StorageInterface $target_storage
   *   The target storage.
   * @param \Drupal\Core\Config\StorageInterface $source_storage
   *   The source storage
   */
  public function __construct(StorageInterface $target_storage, StorageInterface $source_storage) {
    $this->targetStorage = $target_storage;
    $this->sourceStorage = $source_storage;
  }

  /**
   * Downloads a tarball of the site configuration.
   */
  public function downloadExport() {
    $archiver = new ArchiveTar(file_directory_temp() . '/config.tar.gz', 'gz');
    $config_dir = config_get_config_directory();
    $config_files = array();
    foreach (\Drupal::service('config.storage')
      ->listAll() as $config_name) {
      $config_files[] = $config_dir . '/' . $config_name . '.yml';
    }
    $archiver
      ->createModify($config_files, '', config_get_config_directory());
    return file_download('temporary', 'config.tar.gz');
  }

  /**
   * Shows diff of specificed configuration file.
   *
   * @param string $config_file
   *   The name of the configuration file.
   *
   * @return string
   *   Table showing a two-way diff between the active and staged configuration.
   */
  public function diff($config_file) {

    // Add the CSS for the inline diff.
    $output['#attached']['css'][] = drupal_get_path('module', 'system') . '/css/system.diff.css';
    $diff = config_diff($this->targetStorage, $this->sourceStorage, $config_file);
    $formatter = new \DrupalDiffFormatter();
    $formatter->show_header = FALSE;
    $variables = array(
      'header' => array(
        array(
          'data' => t('Old'),
          'colspan' => '2',
        ),
        array(
          'data' => t('New'),
          'colspan' => '2',
        ),
      ),
      'rows' => $formatter
        ->format($diff),
    );
    $output['diff'] = array(
      '#markup' => theme('table', $variables),
    );
    $output['back'] = array(
      '#type' => 'link',
      '#attributes' => array(
        'class' => array(
          'dialog-cancel',
        ),
      ),
      '#title' => "Back to 'Synchronize configuration' page.",
      '#href' => 'admin/config/development/sync',
    );

    // @todo Remove use of drupal_set_title() when
    //   http://drupal.org/node/1871596 is in.
    drupal_set_title(t('View changes of @config_file', array(
      '@config_file' => $config_file,
    )), PASS_THROUGH);
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigController::$sourceStorage protected property The source storage.
ConfigController::$targetStorage protected property The target storage.
ConfigController::create public static function Instantiates a new instance of this controller. Overrides ControllerInterface::create
ConfigController::diff public function Shows diff of specificed configuration file.
ConfigController::downloadExport public function Downloads a tarball of the site configuration.
ConfigController::__construct public function Constructs a ConfigController object.