User still seeing 'View the latest version' tab after scheduled draft is published
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3055911. --> Reported by: [seanb](https://www.drupal.org/user/545912) >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>We just received a bug report from a client that the 'View the latest version' tab is still showing when scheduled draft was published. After discussing this the steps were the following:</p> <ol> <li>Create node A and save as draft (revision ID 1).</li> <li>Edit node A and save as published (revision ID 2).</li> <li>Edit node A again, <b>without making any changes in the content</b> and save as draft again (revision ID 3).</li> <li>Create a scheduled transition for revision ID 3 to change it from draft to published.</li> <li>When the scheduled transition is processed, there are no drafts, the content moderation tab 'View the latest version' is still showing.</li> </ol> <p>After some investigation we found that when the draft doesn't contain any editorial changes the following is a "problem":</p> <p>The scheduled transitions module does a "simple" <code>save()</code> on the entity. </p> <ul> <li><code>ContentEntityStorageBase::populateAffectedRevisionTranslations()</code> calls <code>$translation-&gt;hasTranslationChanges()</code> to determine what the value should be of <code>revision_translation_affected</code>. </li> <li>The <code>hasTranslationChanges()</code> method compares the default revision to the revision we are trying to save.</li> <li>In this case, there are no editorial changes. The default revision has the status "published" and the new revision has that status as well. This means the <code>revision_translation_affected</code> flag is set to <code>FALSE</code> when I think it should be <code>TRUE</code>.</li> </ul> <p>When checking the access for the 'View the latest version' tab, the access relies on <code>ModerationInformation::hasPendingRevision()</code> to determine if the latest translation affected revision is equal to the default revision. It assumes there is a pending revisions if they are not equal.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>I see a couple possible solutions:</p> <ol> <li>When saving a scheduled transition, use <code>setRevisionTranslationAffectedEnforced()</code> to enforce that scheduled status changes enforce that the <code>revision_translation_affected</code> flag is <code>TRUE</code>.</li> <li>Set the revision being changed in the scheduled transition (in our example revision 3) to be <code>$this-&gt;original</code> before saving the entity.</li> <li>Change <code>ModerationInformation::hasPendingRevision()</code> to check if the latest revision is &gt; then the default revision instead of equal/not equal. Not sure if we can assume pending revisions are always newer than the default?</li> </ol> <p>There might be other solutions.</p> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>Decide on the best way to solve/work around this.<br> Write patch.<br> Test.<br> Commit.</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>-</p> <h3 id="summary-api-changes">API changes</h3> <p>-</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>-</p> <h3 id="summary-release-notes">Release notes snippet</h3> <p>-</p> > Related issue: [Issue #2899719](https://www.drupal.org/node/2899719)
issue