captcha_update_8906 hook updating core.extension.yml incorrectly

Created on 19 July 2023, over 1 year ago

Problem/Motivation

As part of the 2.0.1 update, the following hook is updating core.extension.yml incorrectly:

/**
 * Ensure caches are cleared with new module folder locations.
 */
function captcha_update_8906() {
  // Remove test modules if they're on the site. They won't rebuild.
  $extension = \Drupal::configFactory()->getEditable('core.extension');
  $modules = $extension->get('module');
  unset($modules['captcha_long_form_id_test']);
  unset($modules['captcha_test']);
  $extension->set('modules', $modules);
  $extension->save();

  // Need to flush all caches due to module paths changing.
  drupal_flush_all_caches();
}

Note the lines:

$modules = $extension->get('module');

$extension->set('modules', $modules);

The second line should be updating "module", not "modules". This is leading to erroneous data getting added to core.extension.yml.

Steps to reproduce

Run captcha_update_8906 on any Drupal website, export config, notice core.extension.yml get a new modules key.

Proposed resolution

Update the hook to set "module" and not "modules".

🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇦🇺Australia thomwilhelm Sydney

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

Comments & Activities

Production build 0.71.5 2024