Problem/Motivation

Saving the Audit Trail settings form after the effective-delays AJAX preview has fired throws a fatal in validateForm():

Error: Typed property Drupal\audit_trail\Form\AuditTrailSettingsForm::$fileSystem must not be accessed before initialization in ...validateForm() (line 561).

A plain open-and-save works; it only fails once the form has been through an AJAX rebuild, so it looks intermittent.

Steps to reproduce

  • Open the Audit Trail settings form.
  • Change a cron-archive delay field (this fires the effective-delays #ajax preview, so the form is serialized into the form cache).
  • Submit the form. validateForm() fatals as above.

Root cause

The form has #ajax, so Drupal serializes the form object into the form cache. FormBase uses DependencySerializationTrait, whose __wakeup() re-injects service properties by assigning them. The injected file_system property is declared private readonly. The wakeup assignment needs the property both writable and reachable: readonly forbids writes outside the constructor, and a private service property is not reliably re-injected (it serializes under a mangled class-scoped name). Either way the property is left uninitialized and validateForm() trips "accessed before initialization".

Proposed resolution

Declare the injected service protected and non-readonly so DependencySerializationTrait can re-inject it on wakeup:

protected FileSystemInterface $fileSystem,

More broadly, injected service properties on any serializable class that uses DependencySerializationTrait (forms with #ajax or multistep, controllers, plugins) should be protected and not readonly.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mably created an issue. See original summary.

mably’s picture

Status: Active » Needs review

  • mably committed b1edeaff on 1.x
    fix: #3593033 Settings form fatals with "Typed property $fileSystem must...
mably’s picture

Status: Needs review » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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