You are here

public static function SplitImportExportSubscriber::getSubscribedEvents in Configuration Split 2.0.x

File

src/EventSubscriber/SplitImportExportSubscriber.php, line 47

Class

SplitImportExportSubscriber
Event subscriber to react to config transformations.

Namespace

Drupal\config_split\EventSubscriber

Code

public static function getSubscribedEvents() {

  // We get the splits priority from the settings.
  // Unfortunately we can not load the existing splits from the drupal because
  // the subscribed events is compiled into the container in a compiler pass
  // and at that point we can not access the container yet of course.
  // Splits which do not have their priority explicitly set will still be
  // ordered as usual but will be subscribed with priority 0.
  $splits = Settings::get('config_split_priorities', []);

  // The splits not explicitly listed go in the default.
  $exportSubscriptions = [
    [
      'exportDefaultPriority',
      0,
    ],
  ];
  $importSubscriptions = [
    [
      'importDefaultPriority',
      0,
    ],
  ];
  foreach ($splits as $name => $priority) {

    // Use the priority for exporting.
    $exportSubscriptions[] = [
      '_exportExplicit_' . $name,
      $priority,
    ];

    // Use the reverse priority for importing.
    $importSubscriptions[] = [
      '_importExplicit_' . $name,
      -$priority,
    ];
  }

  // Subscribe all the splits mentioned.
  return [
    'config.transform.export' => $exportSubscriptions,
    'config.transform.import' => $importSubscriptions,
  ];
}