Problem/Motivation

When we have a config override in settings.php that overrides a fake key stored in the database like this:
$config['cocoon_media.settings']['cocoon_media']['api_key'] = 'xxxxxxxxxxxxxxxxxxx';
We get an error when trying to add cocoon media (/media/add/cocoon_media_add).

Steps to reproduce

Use the admin interface to set a dummy cocoon media api key (/admin/config/media/cocoon_media_settings).

settings.php

$config['cocoon_media.settings']['cocoon_media']['api_key'] = 'the-correct-key';

Now try to add cocoon media (/media/add/cocoon_media_add). This should fail. Then override this dummy key with a config override in settings.php. Now try again to add cocoon media. This still fails.

Proposed resolution

The CMMAddMediaForm class extends ConfigFormBase, which uses editable config that cannot be overriden with config in settings.php. There are no changes done to the configuration in this class, so it has no need for editable config. Let the class extend FormBase, and inject the ConfigFactory service to get immutable config.

Remaining tasks

See patch, it needs review.

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

ttadegraaff created an issue. See original summary.

thomasdegraaff’s picture

StatusFileSize
new989 bytes
thomasdegraaff’s picture

Status: Active » Needs review

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

thomasdegraaff’s picture

StatusFileSize
new932 bytes
new494 bytes

Removes testing code in patch #2.

himanshu_jhaloya’s picture

Assigned: Unassigned » himanshu_jhaloya
himanshu_jhaloya’s picture

Assigned: himanshu_jhaloya » Unassigned
thomasdegraaff’s picture

Issue summary: View changes
thomasdegraaff’s picture

This patch replaces previous fix #5 that circumvents the actual problem with a real fix of the problem.

scuba_fly’s picture

Assigned: Unassigned » scuba_fly
Status: Needs review » Reviewed & tested by the community

Nice catch!

I've reviewed and tested your code.
The only issue is that the "test api" button does not use the settings from settings.php.

Now I don't know if that is a good or a bad thing.

I'll add this in the module, and add a description below the button that it uses the filled in API key.

scuba_fly’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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