You are here

public function ConfigImportSubscriber::onConfigImporterValidate in Drupal 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
  2. 8 core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php \Drupal\content_moderation\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
Same name and namespace in other branches
  1. 9 core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php \Drupal\content_moderation\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()

Checks that the configuration synchronization is valid.

Parameters

ConfigImporterEvent $event: The config import event.

Overrides ConfigImportValidateEventSubscriberBase::onConfigImporterValidate

File

core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php, line 46

Class

ConfigImportSubscriber
Check moderation states are not being used before updating workflow config.

Namespace

Drupal\content_moderation\EventSubscriber

Code

public function onConfigImporterValidate(ConfigImporterEvent $event) {
  foreach ([
    'update',
    'delete',
  ] as $op) {
    $unprocessed_configurations = $event
      ->getConfigImporter()
      ->getUnprocessedConfiguration($op);
    foreach ($unprocessed_configurations as $unprocessed_configuration) {
      if ($workflow = $this
        ->getWorkflow($unprocessed_configuration)) {
        if ($op === 'update') {
          $original_workflow_config = $event
            ->getConfigImporter()
            ->getStorageComparer()
            ->getSourceStorage()
            ->read($unprocessed_configuration);
          $workflow_config = $event
            ->getConfigImporter()
            ->getStorageComparer()
            ->getTargetStorage()
            ->read($unprocessed_configuration);
          $diff = array_diff_key($workflow_config['type_settings']['states'], $original_workflow_config['type_settings']['states']);
          foreach (array_keys($diff) as $state_id) {
            $state = $workflow
              ->getTypePlugin()
              ->getState($state_id);
            if ($workflow
              ->getTypePlugin()
              ->workflowStateHasData($workflow, $state)) {
              $event
                ->getConfigImporter()
                ->logError($this
                ->t('The moderation state @state_label is being used, but is not in the source storage.', [
                '@state_label' => $state
                  ->label(),
              ]));
            }
          }
        }
        if ($op === 'delete') {
          if ($workflow
            ->getTypePlugin()
            ->workflowHasData($workflow)) {
            $event
              ->getConfigImporter()
              ->logError($this
              ->t('The workflow @workflow_label is being used, and cannot be deleted.', [
              '@workflow_label' => $workflow
                ->label(),
            ]));
          }
        }
      }
    }
  }
}