Problem/Motivation
Several classes declare injected services as private or private readonly/protected readonly constructor-promoted properties, but all extend base classes (FormBase, ConfigFormBase, ConfirmFormBase, EntityListBuilder) using core's DependencySerializationTrait. Its __wakeup() reassigns service properties from the parent's scope after unserialization — it can't see private properties at all, and can't reinitialize readonly ones (PHP only allows one-time init from the declaring class's own scope). Result: fatal errors on readonly properties, and silent serialization breakage + PHPStan errors (dependencySerializationTraitProperty.unsupportedPrivateProperty/unsupportedReadOnlyProperty) on private ones.
Error: Cannot initialize readonly property Drupal\ai_audio_generator\Form\SettingsForm::$entityTypeManager from scope
Drupal\Core\Form\FormBase in Drupal\Core\Form\FormBase->__wakeup()
Affected files:
- Form/SettingsForm.php (fixed here)
- Form/NodeAudioGenerateForm.php
- Form/PronunciationDictionaryNodeQuickAddForm.php
- Form/PronunciationDictionaryPromoteForm.php
- Form/PronunciationDictionaryQuickAddForm.php
- Form/PronunciationDictionarySearchForm.php
- PronunciationDictionaryEntryListBuilder.php
Proposed resolution
Change every affected property from private/private readonly/protected readonly to plain protected:
- protected readonly EntityTypeManagerInterface $entityTypeManager,
+ protected EntityTypeManagerInterface $entityTypeManager, Issue fork ai_audio_generator-3611996
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
Comment #4
nnevill