Gin WSODs when is not active anymore after a custom theme negotiator swaps the theme
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3554265. --> Reported by: [penyaskito](https://www.drupal.org/user/959536) Related to !714 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Gin WSODs when is not active anymore after a custom theme negotiator swaps the theme, and Gin has the "Enable sticky action buttons" option enabled.</p> <p>This is a Drupal CMS blocker because that option is always enabled if new Navigation in core is enabled + it affects the ability of Drupal Canvas to keep the selection the editor made in the library media selector from the semi-decoupled theme used for forms.</p> <p>Not to be confused with the related issue <span class="drupalorg-gitlab-issue-link drupalorg-gitlab-link-wrapper"><a href="https://git.drupalcode.org/project/gin/-/work_items/3539391" class="drupalorg-gitlab-link">https://git.drupalcode.org/project/gin/-/work_items/3539391</a></span>:</p> <ul> <li>#3539391 covers visual issues when a negotiation does <i>some theme</i> &rarr; <i>Gin</i></li> <li>This covers a WSOD when a negotiation does <i>Gin</i> &rarr; <i>some theme</i> </li> </ul> <h4 id="summary-steps-reproduce">Steps to reproduce</h4> <pre>"call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "gin_form_after_build" not found or invalid function name"</pre><p>The reason is that Gin is adding an <code>after_build</code> handler, but the Gin theme is not loaded anymore, but the form is already cached by Drupal though. So the <code>after_build</code> still tries to run.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <ul> <li>Move the after_build handler to the same class that is adding it, which will be loaded.</li> <li>Check Gin (or a sub-theme or Gin) is active or early return the form without modifications.</li> </ul> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <p>Review.</p> <h3 id="summary-ui-changes">User interface changes</h3> <p>None, as Gin is not active in that request anymore.</p> <h3 id="summary-api-changes">API changes</h3> <p>AFAIK handlers are not considered API.</p> <h3 id="summary-data-model-changes">Data model changes</h3> <p>None.</p> > Related issue: [Issue #3539391](https://www.drupal.org/node/3539391) > Related issue: [Issue #3531415](https://www.drupal.org/node/3531415)
issue