function ConfigImportSubscriber::onConfigImporterValidate
Same name in this branch
- 9 core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
Same name in other branches
- 8.9.x core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php \Drupal\content_moderation\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
- 8.9.x core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
- 10 core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php \Drupal\content_moderation\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
- 10 core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
- 11.x core/modules/content_moderation/src/EventSubscriber/ConfigImportSubscriber.php \Drupal\content_moderation\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
- 11.x core/lib/Drupal/Core/EventSubscriber/ConfigImportSubscriber.php \Drupal\Core\EventSubscriber\ConfigImportSubscriber::onConfigImporterValidate()
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\EventSubscriberCode
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(),
]));
}
}
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.