Problem/Motivation

It is not possible to save the image widget crop settings.

Saving configuration causes the following error:

Drupal\Core\Config\ImmutableConfigException: Can not set values on immutable configuration image_widget_crop.settings:settings.library_url

Steps to reproduce

1. Install image_widget_crop
2. Go to /admin/config/media/crop-widget
3. Save configuration

Proposed resolution

Use $this->config to get the configuration object, instead of getting it from config.factory.

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

omarlopesino created an issue. See original summary.

omarlopesino’s picture

Status: Active » Needs review

I've created a MR that fixes the problem. Please review, thanks!

omarlopesino changed the visibility of the branch 8.x-2.x to hidden.

mably’s picture

Status: Needs review » Reviewed & tested by the community

Hit by the same problem, can confirm that the contributed patch fixes the problem, thanks!

opi’s picture

Works well with D11.1.1 + IWC dev-2.x 2f10025 , thanks.

joegraduate’s picture

Title: Can't save image widget crop settings in Drupal 11 » Can't save image widget crop settings (ImmutableConfigException)
Issue summary: View changes

Closed #3496678: ImmutableConfigException as a duplicate of this issue. Ideally this should be fixed in 3.0.x-dev first but also backported to 8.x-2.x. @sweetchuck contributed to the closed issue and should also be credited here.

webmestre’s picture

Hello,
the 3.0.x-dev version also produces:

Drupal\Core\Config\ImmutableConfigException: Can not set values on immutable configuration image_widget_crop.settings:settings.library_url. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object in Drupal\Core\Config\ImmutableConfig->set() (line 27 of core/lib/Drupal/Core/Config/ImmutableConfig.php).

I'm using the 11.1.2 Drupal version

joegraduate’s picture

Priority: Normal » Major

Increasing priority to major since it is impossible to save module config currently.

anschinsan’s picture

StatusFileSize
new846 bytes

Fix it by getting settings editable

natefollmer’s picture

StatusFileSize
new781 bytes

Path issue with previous patch that caused patching to fail. I've fixed the paths. This one should work. I can now save settings after applying this patch.

anup.singh made their first commit to this issue’s fork.

anup.singh’s picture

Latest patch are working and it seems to be correct approach, So update the MR with same.

joelpittet made their first commit to this issue’s fork.

joelpittet’s picture

Just ran into this, thanks for putting this together, hopefully this can be merged soon.

solideogloria’s picture

+1 please merge.

jesss’s picture

The MR works for me. I hope this gets merged soon -- this module is unusable without it.

phenaproxima’s picture

Issue tags: +Needs followup

I'm going to merge this to get people unblocked, even though the bug itself is due to a preexisting, incorrect pattern -- you are never supposed to inject a config object into a form (or any class) as a dependency.

The correct pattern would be for the form to override the getEditableConfigNames() method, and use $this->config() internally to load config. Core will guarantee that it gets editable versions of anything listed in getEditableConfigNames().

Merging this on the good-faith assumption that some kindly person will open a follow-up issue in which to do that cleanup.

phenaproxima’s picture

Status: Reviewed & tested by the community » Fixed

The merge train has now left the station! Should be committed shortly when all tests pass.

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

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

Maintainers, please credit people who helped resolve this issue.

joelpittet’s picture

Thanks a bunch @phenaproxima created that follow-up #3545190: Refactor form to use $this->config() instead of injecting config

Status: Fixed » Closed (fixed)

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