drupal_static data will not change each time you set it which breaks integrations like Simple Multistep

Created on 19 November 2024, about 1 month ago

Problem/Motivation

The problem is described here: https://www.drupal.org/project/gin/issues/3468961 🐛 Problem since rc11 with Action buttons Active
Since the actions buttons change with each step with Simple Multistep the drupal_static can't work. I tried implementing the drupal_static_reset but could never get it to clear the previously saved data.

Steps to reproduce

This article was helpful with how drupal_static works - https://drupal.psu.edu/blog/post/implementing-drupalstatic-function-dyna...

Proposed resolution

Try replacing the use of drupal_static (since it is depricated anyway) with the Cache API: something like this:

function _gin_form_actions(?array $actions = NULL): ?array {
  if ($actions !== NULL) {
    // Set the form actions for this request.
    \Drupal::cache('data')->set(__FUNCTION__, $actions, Cache::PERMANENT);
  }
  $actions = \Drupal::cache('data')->get(__FUNCTION__)->data;
  return $actions;
}

I am not a cache expert, the cache ID might need to be more unique to the specific users session but the above solution seems to work on first tests.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇺🇸United States trigdog

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @trigdog
  • Pipeline finished with Failed
    about 1 month ago
    Total: 402s
    #346179
  • Pipeline finished with Failed
    about 1 month ago
    Total: 281s
    #346183
  • 🇺🇸United States trigdog

    The merge request seems to fix the problem for the simple_multistep module on first test but I do not know how it would affect the others calls to the _gin_form_actions function in top_bar.theme and local_actions.theme because I have to clear it once it is used or it shows up on pages you don't want it to.

    drupal_static seems to be for static content. The simple_mutliform module uses dynamic action buttons during each step. Sometimes a next button will appear, or a back button or both. The save and preview buttons are also hidden and unhidden using the #access property depending on the step in the process. These dynamic changes do not seem work with drupal_static. We may be able to modify the use of drupal_static with a unique name parameter for each step but I couldn't think of a way to call the unique names in page.theme.

  • 🇺🇸United States trigdog

    After more digging, it seems this may be caused by the simple_multiform call to rebuild their form_alter so any step after the first step is calling the gin_form_alter twice (once for the first load and a second for the rebuild) and drupal_static is not updating the $actions value on the second request. Is there a way make drupal_static work in this scenario?

  • 🇩🇪Germany jurgenhaas Gottmadingen

    The caching approach is not required for this. Instead, we can use a simple static variable to resolve this issue instead of using drupal_static.

    I've fixed that as part of 📌 Improve sticky actions implementation Active and it works with simple_multistep. Please test MR!536 and let us know if that fixes the issue for you as well.

    Note: you don't need to create a patch for testing this. You can either check out the branch of that MR or you use https://git.drupalcode.org/project/gin/-/merge_requests/536.diff as your patch. This is the best way for testing, as long as you don't do that in production, as that patch can change over time, until it will be finally merged.

  • 🇮🇳India diwakar07

    Hi,
    Since the issue https://www.drupal.org/project/gin/issues/3468961 🐛 Problem since rc11 with Action buttons Active , mentioned in the issue summary has been reviewed and fixed, this shall be moved as well.

    I have already reviewed MR !536, it successfully fixed the button issue with Simple Multistep module, and module seems to be working fine with gin.
    Hence moving this to RTBC!

    Thanks.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    Thanks for testing and feedback @diwakar07. Marking this as fixed and granting issue credits, the fix will be merged with the related issue asap.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024