I have two languages (English and French). I want to:
- Explore options to create/review/approve/publish English content
as its own workflow
- Explore options to create/review/approve/publish French content
as its own workflow
- There should be no dependency between English moderation flow and
French moderation flow
- After published, if there's any need to modifify the content, the content can be again send back. Anonymous users will be seeing the last published version of the page until the modified page is again published
Reviewers have the permission to only view a page if its status is Review.
I tried the following solutions:
Workflow condition: When only Published is set as Default Revision.
Any language is working properly, but when there is a translation and one of the language is published, even though when we change the moderation state of the node in the other language, the current revision status is still sitting on the last published revision of the node regardless of the language and the moderation state of the latter is staying on draft as database isn't getting updated (even though we changed it to review or approved). As a result the Reviewer is not able to view the translated page, since it is still in draft. Since a revision is available, the reviewer has to go the particular revision and view the page. This is not desired: Reviewers shouldn't be bothered with the node ID.
Workflow condition: When only Review and Approved both are set as Default Revision.
Both the languages are now independent; both can be published individually. Changing any of the revisions back to Review or Approved to modify the existing node content unpublishes it. As a result, anonymous users aren't anymore able to see the page.
I tried to implement hook_entity_update()
to update content_moderation_state_field_data.
function sync_revision_node_update(EntityInterface $entity) {
$entity_type = $entity->getEntityTypeId();
if ($entity_type == "node") {
$entity_id = $entity->id();
$vid = \Drupal::entityTypeManager()->getStorage('node')
->getLatestRevisionId($entity_id);
$langcode = $entity->get('langcode')->value;
$moderationState = $entity->moderation_state->value;
if ($moderationState != "published") {
$table = 'content_moderation_state_field_data';
$query = \Drupal::database()->update($table)
->fields(array(
'moderation_state' => $moderationState,
'content_entity_revision_id' => $vid,
))
->condition('content_entity_id', $entity_id)
->condition('langcode', $langcode)->execute();
}
}
}
This is updating the 'content_moderation_state_field_data' table but the /fr/test page is still not in review. It is still staying in draft. The reviewers needs to go the latest revision and view the page (/fr/node/$node_id/latest), but this isn't desired. The reviewers shouldn't bother about the node ID.
I tried to write a preprocess hook that shall redirect to the latest revision.
function sync_revision_preprocess_page(&$variables) {
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
$nid = $node->id();
$vid = \Drupal::entityTypeManager()
->getStorage('node')
->getLatestRevisionId($nid);
$moderationState = $node->moderation_state->value;
$langcode = $node->get('langcode')->value;
$url = $_SERVER['REQUEST_URI'];
if ($moderationState != "published" && strpos($url,'latest') == false) {
$path = "/" . $langcode . "/" . "node/" . $nid . "/" . "latest";
$response = new RedirectResponse($path);
$response->send();
}
}
}
This not working as expected. The /fr/test is first getting a 403 error and hence the redirect is not working.
Please suggest a better working approach to fit in all these criteria.