Call to unknown method: Drupal\Core\Config\ConfigBase::save()PHP(PHP0418)

My code:

public function submitForm(array &$form, FormStateInterface $form_state): void
{
    // Update the configuration.
    $this->configFactory->getEditable(static::SETTINGS)
      // Set the submitted configuration setting.
      ->set('pacer_site_mode', $form_state->getValue('pacer_site_mode'))
      ->set('contact_log_email', $form_state->getValue('contact_log_email'))
      ->save();

    parent::submitForm($form, $form_state);
}

The save method is in the class Config and StorageConfig

    DonaldWinston Thank you for reporting the issue.

    I've tried, but probably with a different Drupal version (mine is 9.3).

    My first guess would be that it might happen when not all the files are processed by our extension, yet. Is the "Processing" in the status bar complete?

      No there's no "Processing" text. It's looking for the "save()" method in the class "ConfigBase" for some reason. I believe it is supposed to just "Config". "StorageConfig" inherits from it.

        DonaldWinston It's because the method set() returns ConfigBase

        I think we should be "smarter" in this case, and expect the annotation/documentation may not be absolutely correct.

          JakubMisek All I see is the {@inheritdoc} annotation. I guess I'll just ignore it. Maybe it will go away in version 10.

            I changed the code like this and problem went away:

            $config = $this->configFactory->getEditable(static::SETTINGS);
            // Set the submitted configuration setting.
            $config->set('pacer_site_mode', $form_state->getValue('pacer_site_mode'));
            $config->set('contact_log_email', $form_state->getValue('contact_log_email'));
            $config->save();

            In addition, some other problems went away when I dropped the Drupal 10 code in my VSCode project.

              Write a Reply...