2
  1. My workflow is draft, publish and archived.
  2. My translations are 'en(default)', 'fr', and 'de'.
  3. My clients create a lot of nodes in draft status for their release.
  4. We must release these latest revisions in these nodes.
  5. Each nodes has some paragraph field.

I try the following code on drush eval, but "de" translations are changed as first revision in paragaraph field.

$langcode = "fr";
$nid = 12345;
// node loaded
$node = \Drupal\node\Entity\Node::load($nid);
$node = $node->getTranslation($langcode);
if($node->hasTranslation($langcode)){
    // node storage
    $storage = \Drupal::entityTypeManager()->getStorage($node->getEntityTypeId());
    // latest translation revision id
    $revision_id = $storage->getLatestTranslationAffectedRevisionId($nid, $langcode);
    $revision = $storage->loadRevision($revision_id);
    if($revision->hasTranslation($langcode)){
      $revision = $revision->getTranslation($langcode);
      $status = $revision->moderation_state->value;
      $is_draft = $status == "draft";
      if($is_draft){
        $revision->setNewRevision(TRUE);
        $revision->setRevisionCreationTime(REQUEST_TIME);
        $revision->set('moderation_state', 'published');
        $revision->save();
      }
    }
}

How to publish latest revision langcode programmatically in each translation.

Thanks.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.