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

Created on 19 November 2024, 2 days ago

Problem/Motivation

The problem is described here: https://www.drupal.org/project/gin/issues/3468961 πŸ› Problem since rc11 with Action buttons Postponed: needs info
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
  • πŸ‡ΊπŸ‡ΈUnited States trigdog
  • Pipeline finished with Failed
    about 15 hours ago
    Total: 402s
    #346179
  • Pipeline finished with Failed
    about 15 hours 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?

Production build 0.71.5 2024