diff --git a/core/modules/content_moderation/content_moderation.module b/core/modules/content_moderation/content_moderation.module
index 4fa13396c9..94264aee99 100644
--- a/core/modules/content_moderation/content_moderation.module
+++ b/core/modules/content_moderation/content_moderation.module
@@ -149,8 +149,8 @@ function content_moderation_entity_access(EntityInterface $entity, $operation, A
$moderation_info = Drupal::service('content_moderation.moderation_information');
$access_result = NULL;
- if ($operation === 'view' && $entity instanceof EntityPublishedInterface) {
- $access_result = (!$entity->isPublished())
+ if ($operation === 'view') {
+ $access_result = (($entity instanceof EntityPublishedInterface) && !$entity->isPublished())
? AccessResult::allowedIfHasPermission($account, 'view any unpublished content')
: AccessResult::neutral();
@@ -160,14 +160,14 @@ function content_moderation_entity_access(EntityInterface $entity, $operation, A
/** @var \Drupal\content_moderation\StateTransitionValidation $transition_validation */
$transition_validation = \Drupal::service('content_moderation.state_transition_validation');
- $permitted_transition_targets = $transition_validation->getPermittedTransitions($entity, $account);
- $access_result = $permitted_transition_targets ? AccessResult::neutral() : AccessResult::forbidden();
+ $valid_transition_targets = $transition_validation->getValidTransitions($entity, $account);
+ $access_result = $valid_transition_targets ? AccessResult::neutral() : AccessResult::forbidden();
$access_result->addCacheableDependency($entity);
$access_result->addCacheableDependency($account);
$workflow = \Drupal::service('content_moderation.moderation_information')->getWorkflowForEntity($entity);
$access_result->addCacheableDependency($workflow);
- foreach ($permitted_transition_targets as $valid_transition_target) {
+ foreach ($valid_transition_targets as $valid_transition_target) {
$access_result->addCacheableDependency($valid_transition_target);
}
}
diff --git a/core/modules/content_moderation/src/EntityTypeInfo.php b/core/modules/content_moderation/src/EntityTypeInfo.php
index 04c43b60d8..4768a4921c 100644
--- a/core/modules/content_moderation/src/EntityTypeInfo.php
+++ b/core/modules/content_moderation/src/EntityTypeInfo.php
@@ -371,12 +371,10 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
->getHandler($entity->getEntityTypeId(), 'moderation')
->enforceRevisionsEntityFormAlter($form, $form_state, $form_id);
- // List invalid transitions.
- $invalid_transitions = array_diff_key($this->validator->getPermittedTransitions($entity, $this->currentUser), $this->validator->getValidTransitions($entity, $this->currentUser));
- if ($invalid_transitions) {
- $labels = array_map(function ($transition) { return $transition->label(); }, $invalid_transitions);
- $invalid_transition_labels = implode(', ', $labels);
+ if (!$entity->isRevisionTranslationAffected() && count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) {
$latest_revision = $this->getTranslationAffectedRevision($this->moderationInfo->getLatestRevision($entity->getEntityTypeId(), $entity->id()));
+ drupal_set_message('A draft revision in another translation is preventing this from being saved.', 'error');
+ $form['actions']['#access'] = FALSE;
$form['invalid_transitions'] = [
'rule' => [
'#type' => 'item',
@@ -385,7 +383,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
'label' => [
'#type' => 'item',
'#prefix' => '',
- '#markup' => \Drupal::translation()->translate('It is not possible to %invalid_transition_labels this @entity_type_label.', ['%invalid_transition_labels' => $invalid_transition_labels, '@entity_type_label' => $entity->getEntityType()->getLabel()]),
+ '#markup' => \Drupal::translation()->translate('It is not possible to save this @entity_type_label.', ['@entity_type_label' => $entity->getEntityType()->getLabel()]),
'#suffix' => '',
],
'message' => [
@@ -393,7 +391,7 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
'#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,
- '#no_valid_transitions' => empty($this->validator->getValidTransitions($entity, $this->currentUser)),
+ '#no_valid_transitions' => TRUE,
];
}
@@ -404,19 +402,6 @@ public function formAlter(array &$form, FormStateInterface $form_state, $form_id
}
/**
- * @param array $variables
- * @param string $hook
- */
- public function preprocess(array &$variables, $hook) {
- // Remove all form fields if there are no valid transitions.
- if (strpos($hook, '_edit_form') && $variables['form']['invalid_transitions']['#no_valid_transitions']) {
- $invalid_transitions = $variables['form']['invalid_transitions'];
- unset($variables['form']);
- $variables['form'] = $invalid_transitions;
- }
- }
-
- /**
* @param \Drupal\Core\Entity\EntityInterface $entity
* @return \Drupal\Core\Entity\EntityInterface
*/
diff --git a/core/modules/content_moderation/src/StateTransitionValidation.php b/core/modules/content_moderation/src/StateTransitionValidation.php
index b8535e32ec..96ade796ec 100644
--- a/core/modules/content_moderation/src/StateTransitionValidation.php
+++ b/core/modules/content_moderation/src/StateTransitionValidation.php
@@ -39,29 +39,12 @@ public function __construct(ModerationInformationInterface $moderation_info) {
* {@inheritdoc}
*/
public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user) {
- $permitted_transitions = $this->getPermittedTransitions($entity, $user);
- // For entities with more than one translation and forward revisions we
- // want to only allow specific transitions.
- if (count($entity->getTranslationLanguages()) > 1 && $this->moderationInfo->hasForwardRevision($entity)) {
- $permitted_transitions = array_filter($permitted_transitions, function(Transition $transition) use ($entity) {
- // The entity needs to be the latest and translation affected.
- return $this->moderationInfo->isLatestRevision($entity) && $entity->isRevisionTranslationAffected();
- });
- }
-
- return $permitted_transitions;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getPermittedTransitions(ContentEntityInterface $entity, AccountInterface $user) {
$workflow = $this->moderationInfo->getWorkflowForEntity($entity);
$current_state = $entity->moderation_state->value ? $workflow->getState($entity->moderation_state->value) : $workflow->getInitialState();
- return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user, $entity) {
+ return array_filter($current_state->getTransitions(), function(Transition $transition) use ($workflow, $user) {
return $user->hasPermission('use ' . $workflow->id() . ' transition ' . $transition->id());
});
}
-}
+}
\ No newline at end of file
diff --git a/core/modules/content_moderation/src/StateTransitionValidationInterface.php b/core/modules/content_moderation/src/StateTransitionValidationInterface.php
index 25dd77d99d..b3da54b335 100644
--- a/core/modules/content_moderation/src/StateTransitionValidationInterface.php
+++ b/core/modules/content_moderation/src/StateTransitionValidationInterface.php
@@ -11,21 +11,6 @@
interface StateTransitionValidationInterface {
/**
- * Gets a list of transitions that are both legal and valid for this user on
- * this entity.
- *
- * @param \Drupal\Core\Entity\ContentEntityInterface $entity
- * The entity to be transitioned.
- * @param \Drupal\Core\Session\AccountInterface $user
- * The account that wants to perform a transition.
- *
- * @return \Drupal\workflows\Transition[]
- * The list of transitions that are both legal and valid for this user on
- * this entity.
- */
- public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user);
-
- /**
* Gets a list of transitions that are legal for this user on this entity.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
@@ -36,6 +21,6 @@ public function getValidTransitions(ContentEntityInterface $entity, AccountInter
* @return \Drupal\workflows\Transition[]
* The list of transitions that are legal for this user on this entity.
*/
- public function getPermittedTransitions(ContentEntityInterface $entity, AccountInterface $user);
+ public function getValidTransitions(ContentEntityInterface $entity, AccountInterface $user);
-}
+}
\ No newline at end of file
diff --git a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
index c6adf47f9b..acbe8d044d 100644
--- a/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
+++ b/core/modules/content_moderation/tests/src/Functional/ModerationFormTest.php
@@ -184,7 +184,7 @@ public function testContentTranslationNodeForm() {
$this->assertFalse($this->xpath('//input[@value="Save and Create New Draft (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]'));
- $this->assertText('It is not possible to Create New Draft, Publish this Content.');
+ $this->assertText('It is not possible to save this Content.');
// Publish the french forward revision (revision 4).
$this->drupalGet('fr/' . $edit_path);
@@ -224,7 +224,7 @@ public function testContentTranslationNodeForm() {
$this->assertFalse($this->xpath('//input[@value="Save and Create New Draft (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]'));
- $this->assertText('It is not possible to Create New Draft, Publish, Archive this Content.');
+ $this->assertText('It is not possible to save this Content.');
// We should be able to publish the english forward revision (revision 7)
$this->drupalGet($edit_path);
@@ -272,7 +272,7 @@ public function testContentTranslationNodeForm() {
$this->assertFalse($this->xpath('//input[@value="Save and Create New Draft (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Publish (this translation)"]'));
$this->assertFalse($this->xpath('//input[@value="Save and Archive (this translation)"]'));
- $this->assertText('It is not possible to Create New Draft, Publish this Content.');
+ $this->assertText('It is not possible to save this Content.');
}
}