I am facing issue with Multi-lingual Content Moderation.
Problem Statement
I have two languages (say, English(default) and French(secondary)). I want to
- Explore options to create / review / approve / publish English content(/en/test) as it’s own workflow
- Explore options to create / review / approve /publish French content(/en/test) as it’s own workflow
- There should be no dependency between English moderation flow and French moderation flow.
- After published If there’s any modification needed in the content, The content can be again send back. But the Anonymous users will be seeing the last published version of the page until the modified page is again published.
Points to consider:
Reviewer has the permission to only view a page if it is in Review state. And this is an important step.
Things that I have tried:
1. Workflow condition: When only Published is set as Default Revision
- Any one language is working properly. But when there is a translation and one of the language(say en) is published, even though when we change the moderation state of the other node(fr), 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(fr) 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(fr/test).(Since the fr is still in draft).But since a revision is available , the reviewer has to go the particular revision and view the page(/fr/node/$node_id/latest) . This is not desired .Reviewer should not be bothered with the node id.
2. Workflow condition: When only Review and Approved both are set as Default Revision
- Both the languages are now independent. Both can be published individually. But changing the any of the revision back to Review or Approved to modify the existing page content is making the page completely unpublished. As a result Anonymous User isn’t anymore able to see the page.
3. Tried to write a hook_entity_update that shall update the content_moderation_state_field_data
function sync_revision_node_update(EntityInterface $entity) { $entity_type = $entity->getEntityTypeId(); dpm("entity type=" . $entity_type); 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 reviewer has to go the latest revision and view the page(/fr/node/$node_id/latest) . But this isn’t desired. The reviewer shouldn’t bother about the node id.
4. 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 DrupalnodeNodeInterface) { $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 properly as expected. The /fr/test is first getting a 403 Access Denied and hence the redirect is not working.
Please suggest a better working approach to fit in all these criteria .I will be grateful.