diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index 8f6ac4d79e..a199f6fd1c 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -292,6 +292,27 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id $form['actions']['submit']['#submit'][] = [EntityTypeInfo::class, 'bundleFormRedirect']; } } + + if ($form_id == 'workflow_state_delete_form') { + $args = $form_state->getBuildInfo()['args']; + /** @var \Drupal\workflows\WorkflowInterface $workflow */ + $workflow = $args[0]; + $state = $args[1]; + $count = $this->entityTypeManager + ->getStorage('content_moderation_state') + ->getQuery() + ->count() + ->condition('moderation_state', $state) + ->execute(); + if ($count > 0) { + $state = $workflow->getState($state); + $new_state = $state->isPublishedState() ? $workflow->getState('published') : $workflow->getState('draft'); + $form['description']['#markup'] = $this->t('This moderation state is assigned to @count. Deleting it will revert these to @new_state.', [ + '@count' => $this->stringTranslation->formatPlural($count, '1 item', '@count items'), + '@new_state' => $new_state->label() + ]); + } + } } /**