- My workflow is draft, publish and archived.
- My translations are 'en(default)', 'fr', and 'de'.
- My clients create a lot of nodes in draft status for their release.
- We must release these latest revisions in these nodes.
- 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.