Prevent deleting Code Components if there are usages in forward revisions
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3549885. --> Reported by: [effulgentsia](https://www.drupal.org/user/78040) >>> <h3 id="overview">Overview</h3> <p><span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3530058" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3530058</a></span> made it so that Canvas prevents you from deleting Code Components if they are being used on a Page's draft content that's in auto-save storage, but does not prevent that if that same draft content is in a forward revision instead of auto-save storage. That makes no sense: for the purpose of considering a Code Component as "in use", draft content should count the same whether it's in auto-save storage or in a forward revision.</p> <p><strong>&#9888;&#65039; Without this, Workspaces may be broken by deleting code components.</strong></p> <h3 id="proposed-resolution">Proposed resolution</h3> <p>Add onto the code that was added in <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/canvas/-/work_items/3530058" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/canvas/-/work_items/3530058</a></span> to also query forward revisions for usage:</p> <pre>index 877f38a2e..abc7c9db1 100644<br>--- a/src/EntityHandlers/VisibleWhenDisabledCanvasConfigEntityAccessControlHandler.php<br>+++ b/src/EntityHandlers/VisibleWhenDisabledCanvasConfigEntityAccessControlHandler.php<br>@@ -78,6 +78,9 @@ final class VisibleWhenDisabledCanvasConfigEntityAccessControlHandler extends Ca<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ))-&gt;orIf(AccessResult::forbiddenIf(<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;componentAudit-&gt;hasUsages($component, RevisionAuditEnum::Default),<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'This code component is in use in a default revision and cannot be deleted.'<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ))-&gt;orIf(AccessResult::forbiddenIf(<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $this-&gt;componentAudit-&gt;hasUsages($component, RevisionAuditEnum::Latest),<br>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'This code component is in use in the latest revision and cannot be deleted.'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ));<br>&nbsp;&nbsp;&nbsp;&nbsp; }</pre><p>However, core's entity query API does not support querying all forward revisions &mdash; it only supports <code>::allRevisions()</code>, <code>::currentRevision()</code> and <code>::latestRevision()</code>.</p> <p>Which presumably means the only way to fetch this information today would be to iterate over all Workspaces, perform a query for each using <code>\Drupal\workspaces\EntityQuery\Query::prepare()</code> to check usage in the latest per-workspace revision? TBD.</p> <h3 id="ui-changes">User interface changes</h3>
issue