Unverified Commit 3ae3e525 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3047812 by bircher, Krzysztof Domański, alexpott, ricardoamaro,...

Issue #3047812 by bircher, Krzysztof Domański, alexpott, ricardoamaro, larowlan, borisson_, mpotter: Add a Config Transformation event dispatching during config import and export
parent 86736407
Loading
Loading
Loading
Loading
+9 −0
Changes for core/modules/config_environment/config_environment.module: 9 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,15 @@
 * Allows site administrators to modify environment configuration.
 */

// Set class aliases for the classes that will go into core when we are in beta.
// See the experimental modules policy https://www.drupal.org/core/experimental
// @todo: remove class aliases in #2991683
@class_alias('Drupal\config_environment\Core\Config\StorageTransformEvent', 'Drupal\Core\Config\StorageTransformEvent');
@class_alias('Drupal\config_environment\Core\Config\ManagedStorage', 'Drupal\Core\Config\ManagedStorage');
@class_alias('Drupal\config_environment\Core\Config\StorageManagerInterface', 'Drupal\Core\Config\StorageManagerInterface');
@class_alias('Drupal\config_environment\Core\Config\ExportStorageManager', 'Drupal\Core\Config\ExportStorageManager');
@class_alias('Drupal\config_environment\Core\Config\ImportStorageTransformer', 'Drupal\Core\Config\ImportStorageTransformer');

use Drupal\Core\Routing\RouteMatchInterface;

/**
+31 −0
Changes for core/modules/config_environment/config_environment.routing.yml: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
# @todo: Stop taking over config module routes in #2991683
config.sync:
  path: '/admin/config/development/configuration'
  defaults:
    _form: '\Drupal\config_environment\Form\ConfigSync'
    _title: 'Synchronize'
  requirements:
    _permission: 'synchronize configuration'

config.diff:
  path: '/admin/config/development/configuration/sync/diff/{source_name}/{target_name}'
  defaults:
    _controller: '\Drupal\config_environment\Controller\ConfigController::diff'
    target_name: NULL
  requirements:
    _permission: 'synchronize configuration'

config.diff_collection:
  path: '/admin/config/development/configuration/sync/diff_collection/{collection}/{source_name}/{target_name}'
  defaults:
    _controller: '\Drupal\config_environment\Controller\ConfigController::diff'
    target_name: NULL
  requirements:
    _permission: 'synchronize configuration'

config.export_download:
  path: '/admin/config/development/configuration/full/export-download'
  defaults:
    _controller: '\Drupal\config_environment\Controller\ConfigController::downloadExport'
  requirements:
    _permission: 'export configuration'
+13 −0
Changes for core/modules/config_environment/config_environment.services.yml: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
services:
  # @todo: Move this back to core services in #2991683
  config.import_transformer:
    class: Drupal\config_environment\Core\Config\ImportStorageTransformer
    arguments: ['@event_dispatcher', '@database']
  config.storage.export:
    class: Drupal\config_environment\Core\Config\ManagedStorage
    arguments: ['@config.storage.export.manager']
  config.storage.export.manager:
    class: Drupal\config_environment\Core\Config\ExportStorageManager
    arguments: ['@config.storage', '@state', '@database', '@event_dispatcher']
    tags:
      - { name: event_subscriber }
+47 −0
Changes for core/modules/config_environment/src/Controller/ConfigController.php: 47 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\config_environment\Controller;

use Drupal\config\Controller\ConfigController as OriginalConfigController;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Returns responses for config module routes.
 */
class ConfigController extends OriginalConfigController {

  /**
   * The import transformer service.
   *
   * @var \Drupal\Core\Config\ImportStorageTransformer
   */
  protected $importTransformer;

  /**
   * The sync storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $syncStorage;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $controller = parent::create($container);
    $controller->importTransformer = $container->get('config.import_transformer');
    $controller->syncStorage = $container->get('config.storage.sync');

    return $controller;
  }

  /**
   * {@inheritdoc}
   */
  public function diff($source_name, $target_name = NULL, $collection = NULL) {
    $this->sourceStorage = $this->importTransformer->transform($this->syncStorage);

    return parent::diff($source_name, $target_name, $collection);
  }

}
+79 −0
Changes for core/modules/config_environment/src/Core/Config/ConfigEvents.php: 79 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

// @codingStandardsIgnoreStart
// @todo: Move this back to \Drupal\Core\Config\ConfigEvents in #2991683.
// @codingStandardsIgnoreEnd
namespace Drupal\config_environment\Core\Config;

/**
 * Defines events for the configuration transform system.
 *
 * The constants in this class will be moved back into ConfigEvents.
 * But due to the fact that the config_environment is not in beta we save their
 * definitions here and use the literal strings in the mean time.
 *
 * @internal
 *
 * @deprecated The class will be merged with Drupal\Core\Config\ConfigEvents.
 */
final class ConfigEvents {

  /**
   * Name of the event fired just before importing configuration.
   *
   * This event allows subscribers to modify the configuration which is about to
   * be imported. The event listener method receives a
   * \Drupal\Core\Config\StorageTransformEvent instance. This event contains a
   * config storage which subscribers can interact with and which will finally
   * be used to import the configuration from.
   * Together with \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT
   * subscribers can alter the active configuration in a config sync workflow
   * instead of just overriding at runtime via the config-override system.
   * This allows a complete customisation of the workflow including additional
   * modules and editable configuration in different environments.
   *
   * @code
   *   $storage = $event->getStorage();
   * @endcode
   *
   * This event is also fired when just viewing the difference of configuration
   * to be imported independently of whether the import takes place or not.
   * Use the \Drupal\Core\Config\ConfigEvents::IMPORT event to subscribe to the
   * import having taken place.
   *
   * @Event
   *
   * @see \Drupal\Core\Config\StorageTransformEvent
   * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_EXPORT
   *
   * @var string
   */
  const STORAGE_TRANSFORM_IMPORT = 'config.transform.import';

  /**
   * Name of the event fired when the export storage is used.
   *
   * This event allows subscribers to modify the configuration which is about to
   * be exported. The event listener method receives a
   * \Drupal\Core\Config\StorageTransformEvent instance. This event contains a
   * config storage which subscribers can interact with and which will finally
   * be used to export the configuration from.
   *
   * @code
   *   $storage = $event->getStorage();
   * @endcode
   *
   * Typically subscribers will want to perform the reverse operation on the
   * storage than for \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_IMPORT
   * to make sure successive exports and imports yield no difference.
   *
   * @Event
   *
   * @see \Drupal\Core\Config\StorageTransformEvent
   * @see \Drupal\Core\Config\ConfigEvents::STORAGE_TRANSFORM_IMPORT
   *
   * @var string
   */
  const STORAGE_TRANSFORM_EXPORT = 'config.transform.export';

}
Loading