How do I unpublish translations when the english content is unpublished? I tried to unpublish the language content programmatically when I am unpublishing the english content in the hook_node_update()
but it returns below error.
$languages = getLanguageList();
$currLanguage = \Drupal::languageManager()->getCurrentLanguage()->getId();
if (!$node->status->value) {
foreach ($languages as $languageId => $language) {
if ($languageId != 'en' && $currLanguage == 'en') {
if ($node->hasTranslation($languageId)) {
$transNode = $node->getTranslation($languageId);
$transNode->setPublished(false);
$transNode->save();
}
}
}
}
Error :
Uncaught PHP Exception Drupal\\Core\\Entity\\EntityStorageException: "Update existing 'node' entity revision while changing the revision ID is not supported."
So I guess if I can do this after saving the node it would work. Is there a hook for node after save. Or is there a way to unpublish language contents of a node while unpublishing the source language(English)?
$node->language()->getId() == 'en'
?