diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php index e4be017..9fa049c 100644 --- a/core/modules/content_moderation/src/EntityTypeInfo.php +++ b/core/modules/content_moderation/src/EntityTypeInfo.php @@ -14,6 +14,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationInterface; @@ -25,6 +26,7 @@ use Drupal\content_moderation\Routing\EntityModerationRouteProvider; use Drupal\content_moderation\Routing\EntityTypeModerationRouteProvider; use Symfony\Component\DependencyInjection\ContainerInterface; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * Manipulates entity type information. @@ -370,7 +372,8 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id ->enforceRevisionsEntityFormAlter($form, $form_state, $form_id); if (empty($this->validator->getValidTransitions($entity, $this->currentUser))) { - drupal_set_message(t('This @entity_type_label cannot be saved, please publish or revert all draft revisions first.', ['@entity_type_label' => $entity->getEntityType()->getLabel()]), 'error'); + $latest_revision = $this->getTranslationAffectedRevision($this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id())); + drupal_set_message(\Drupal::translation()->translate('This @entity_type_label cannot be saved, publish or delete the latest revision first.', ['@entity_type_label' => $entity->getEntityType()->getLabel(), '@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), 'error'); } $invalid_transitions = array_diff_key($this->validator->getPermittedTransitions($entity, $this->currentUser), $this->validator->getValidTransitions($entity, $this->currentUser)); @@ -378,11 +381,22 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id $labels = array_map(function ($transition) { return strtolower($transition->label()); }, $invalid_transitions); $last = array_pop($labels); $invalid_transitions_string = implode(', ', $labels) . ', or ' . $last; + $latest_revision = $this->getTranslationAffectedRevision($this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id())); $form['invalid_transitions'] = [ - '#type' => 'item', - '#prefix' => '', - '#markup' => t('It is not possible to @invalid this @entity_type_label until all draft revisions are published or reverted.', ['@invalid' => $invalid_transitions_string, '@entity_type_label' => $entity->getEntityType()->getLabel()]), - '#suffix' => '', + 'rule' => [ + '#type' => 'item', + '#markup' => '
', + ], + 'label' => [ + '#type' => 'item', + '#prefix' => '', + '#markup' => \Drupal::translation()->translate('It is not possible to @invalid this @entity_type_label.', ['@invalid' => $invalid_transitions_string, '@entity_type_label' => $entity->getEntityType()->getLabel()]), + '#suffix' => '', + ], + 'message' => [ + '#type' => 'item', + '#markup' => \Drupal::translation()->translate('Publish or delete the latest revision to allow all workflow transitions.', ['@latest_revision_edit_url' => $latest_revision->toUrl('edit-form', ['language' => $latest_revision->language()])->toString(), '@latest_revision_delete_url' => $latest_revision->toUrl('delete-form', ['language' => $latest_revision->language()])->toString()]), + ], '#weight' => 999, ]; } @@ -394,6 +408,23 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id } /** + * @param \Drupal\Core\Entity\EntityInterface $entity + * @return \Drupal\Core\Entity\EntityInterface + */ + protected function getTranslationAffectedRevision(EntityInterface $entity) { + if ($entity->isRevisionTranslationAffected()) { + return $entity; + } + /** @var \Drupal\Core\Language\LanguageInterface $language */ + foreach ($entity->getTranslationLanguages() as $language) { + $translation = $entity->getTranslation($language->getId()); + if ($translation->isRevisionTranslationAffected()) { + return $translation; + } + } + } + + /** * Redirect content entity edit forms on save, if there is a forward revision. * * When saving their changes, editors should see those changes displayed on