Settings form is not accessing config correctly.

Created on 18 August 2023, over 1 year ago
Updated 23 October 2023, about 1 year ago

Problem/Motivation

In the settingsForm which is a child of ConfigFormBase, \Drupal\siteimprove\Form\SettingsForm::buildForm is not access config correctly for the settings form as described in Working with Configuration Forms

It is currently calling the configFactory to get the config. Which is fine except is it allow overriden values to be saved in config when depending on how these are set these could be loaded from secrets depending on the system.

Steps to reproduce

in yours settings.php add the following lines.

$config['siteimprove.settings']['api_username'] = 'xxx';
$config['siteimprove.settings']['api_key'] = 'xxx';

Proposed resolution

on the settings form on line 108 which is

    $config = $this->configFactory->get('siteimprove.settings');

this needed to be changed to

    $config = $this->config('siteimprove.settings');

Now the value which is stored in config will display and not the overriden values.

For the API checked we will need to get the values from the real config factory so that they can be run.

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇦🇺Australia gordon Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @gordon
  • 🇮🇳India mukhtarm

    please review the patch

  • Status changed to Needs review over 1 year ago
  • Status changed to RTBC over 1 year ago
  • 🇮🇳India keshavv India

    Confirmed that the given solution works.

    Updated settings.php file

    Before patch

    After patch

  • Status changed to Needs work over 1 year ago
  • 🇦🇺Australia gordon Melbourne

    Hi

    Thanks for this but this change then breaks the republish check.

    So in my clients case we override the user and api key and set these fields to ‘’ in config. So when loading this page it will do the checks with user and api key set to null were it should be using the overridden value.

    There needs to be a change further down where the check will be done not using $config but using a a different version of the config using configFactory() and then the creds will be loaded correctly if they are overridden.

    Thanks for the fast work.
    Gordon.

  • Status changed to Needs review over 1 year ago
  • 🇦🇺Australia gordon Melbourne

    Hi,

    I have changed this into an issue fork and added the necessary changes so that when it does the API check it will use the real config which includes any overrides.

  • @gordon opened merge request.
  • 🇦🇺Australia gordon Melbourne

    I have removed the original patch.

  • 🇩🇰Denmark bartvig

    We have a conflict with https://www.drupal.org/project/siteimprove/issues/3308624 💬 Question with Config Overrides/Key module Fixed

    In that issue, the code was specifically changed from $config = $this->config('siteimprove.settings'); to $config = $this->configFactory->get('siteimprove.settings'); to allow config overrides.

  • 🇩🇰Denmark bartvig

    Oh, I think I understand the issue now. You don't want the overridden value to be displayed in the settings form, but the overridden should still be used in API calls.

  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024