Issue #3638122: Use '#config_target' in the settings forms

Summary

Uses #config_target in the settings forms of Admin Toolbar, Admin Toolbar Tools and Admin Toolbar Search, so Drupal loads, validates and saves the settings from the configuration schema.

Closes #3638122 (child of #3565209)

Changes

  • Added #config_target to the form elements of the three settings forms, and removed the #default_value properties and the manual saving in submitForm().
  • Used core's RedundantEditableConfigNamesTrait instead of getEditableConfigNames().
  • The Menu depth select options and the #min and #max of max_bundle_number come from the Range constraints of the configuration schema.
  • The hoverIntent timeout uses a ConfigTarget with toConfig to cast the select value to an integer, as expected by the schema's Choice constraint.
  • The labels, descriptions and other texts stay in $this->t(), so the existing translations still apply. The only text change: the hover intent link is now built with Link and has rel="noopener noreferrer".
  • The tools form still uses MenuLinkRebuildManager::rebuildNow() after saving.
  • admin_toolbar_update_8007() sets sticky_behavior to enabled if it does not exist. The setting was added without an update hook and is now required by the schema.
  • Updated the comments in the three configuration schemas, which said the labels and descriptions are used by the forms.

Tests

  • AdminToolbarSettingsFormTest: checks the saved values and their types (booleans, integers, the sticky behavior value).
  • AdminToolbarToolsSettingsFormTest: checks a value above the maximum is rejected and the saved max_bundle_number (integer) and show_local_tasks (boolean) values.
  • AdminToolbarSearchSettingsFormTest: checks the three settings are saved as booleans.
  • New Kernel test AdminToolbarUpdateHooksTest for admin_toolbar_update_8007().
  • The per-file sed line for the new test is added to the "phpstan (previous major)" CI job.

Testing

  • Tested locally on Drupal 11.5: the three form Functional tests, the Kernel tests of the three modules and AdminToolbarToolsTest.
  • PHPCS and PHPStan are clean on the changed files.
  • #config_target and the ConfigTarget toConfig argument are available from Drupal 10.2, so they are compatible with ^10.3.
  • Not tested yet: the Drupal 10.3 and 12.x pipelines.

Notes

  • When the Drupal 12 changes (#3594696) are merged, the new Kernel test needs the #[Group] and #[RunTestsInSeparateProcesses] attributes.
  • The tools form still checks moduleExists('toolbar'). This will conflict with the cleanup of #3576945, whichever is merged second.
Edited by David Suissa

Merge request reports

Loading
Loading