Closed (outdated)
Project:
Web Experience Toolkit
Version:
8.x-3.018
Component:
Code
Priority:
Major
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
12 Dec 2020 at 13:27 UTC
Updated:
20 Jul 2021 at 15:30 UTC
Jump to comment: Most recent
Comments
Comment #2
joseph.olstadyou shouldn't have to set a new revision when creating nodes programmatically unless there's a specific reason to, what are you trying to do?
Comment #3
joseph.olstadremove these two lines from your script or module code:
Comment #4
Paramvir Dalal commentedIn short we have to save data from a web form, which has English section and French section, which all gets submitted in one go, and gets saved in a node partly in english translation and partly in the french translation of it, (saving it twice once for each translation).(Create New Revision is enabled for this node, in the configuration itself.)
When we are done saving the content, everything works fine till we publish the content, (every save happens twice, once for each translation)
Post publishing is where the problem is, we need to initiate the change workflow, we try to programmatically change the moderation state to draft, but it gets changed only for English revision, while the French revision state remains as published. below is the code.
$node = $node_storage->load($nid);
//setting some english fields here
$node->moderation_state->value = 'draft';
$node->save();
$node_fr = $node->getTranslation('fr');
//setting some french fields here
$node_fr->moderation_state->value = 'draft';
$node_fr->save();
Adding the below 2 lines of code before each save, seem to make the above work OK.
$node->setNewRevision(TRUE);
$node->setDefaultRevision(FALSE);
Any ideas, what is going on?
Comment #5
joseph.olstadThis might help:
if that isn't sufficient, save the english node, then register a shutdown function to add the french translation
in your addNodeTranslation function you'll add the translation, setRevisionTranslationAffected if you want the same revision id
Comment #6
joseph.olstadI'm not sure why you're adding a revision, just let the save do the work?
However since you're having so much fun
if you want to debug a shutdown function, you will need to write to a log file or log to watchdog, nothing will display to the screen
The shutdown call runs after the english is saved to the database
You might not need the shutdown call, try the two boolean settings first
Comment #7
Paramvir Dalal commentedThanks very much for the advice.
$node->setSyncing(TRUE);
$node->setRevisionTranslationAffected(TRUE);
The above boolean settings are not helping.
Even what we think is working -
$node->setNewRevision(TRUE);
$node->setDefaultRevision(FALSE);
does not seem to be truly consistent, not 100%.
The french translation does not seem to be changing its state inline with the english (default) translation, whatever we do.
Even when we are publishing the node, we have to publish the fr node separately.
Isn't there a way to apply moderation_state change to all the translations in one go?
Comment #8
sylus commented