Problem/Motivation

SettingsForm's constructor declares its injected services ($entityTypeManager, $entityFieldManager, $aiProvider) as readonly.
ConfigFormBase/FormBase use core's DependencySerializationTrait, which reassigns these properties in __wakeup() after the form is unserialized (e.g. from cache/batch/queue). PHP forbids reinitializing a readonly property from outside its declaring class scope, so this throws:

  Error: Cannot initialize readonly property Drupal\ai_audio_generator\Form\SettingsForm::$entityTypeManager from scope                   
  Drupal\Core\Form\FormBase in Drupal\Core\Form\FormBase->__wakeup() (line 80 of core/lib/Drupal/Core/DependencySerializationTrait.php). 

Proposed resolution

Remove readonly from the three constructor-promoted properties — incompatible with DependencySerializationTrait.

  -    protected readonly EntityTypeManagerInterface $entityTypeManager,                                                                  
  -    protected readonly EntityFieldManagerInterface $entityFieldManager,                                                                
  -    protected readonly AiProviderPluginManager $aiProvider,                                                                            
  +    protected EntityTypeManagerInterface $entityTypeManager,                                                                           
  +    protected EntityFieldManagerInterface $entityFieldManager,                                                                         
  +    protected AiProviderPluginManager $aiProvider,
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

nnevill created an issue. See original summary.

  • nnevill committed 731d225c on 1.0.x
    fix: #3611977 SettingsForm:: fatal error: Cannot initialize readonly...
nnevill’s picture

Status: Active » 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.

scott_euser’s picture

Looks like this introduced phpstan issue though

nnevill’s picture

Found 21 phpstan issues - will create a follow-up issue