Too few arguments to function Drupal\Core\Form\ConfigFormBase

Created on 23 February 2025, 1 day ago

Problem/Motivation

Drupal 11 introduced changes in how ConfigFormBase is structured. The constructor now requires two arguments:

ArgumentCountError: Too few arguments to function Drupal\Core\Form\ConfigFormBase::__construct(), 1 passed in ......./modules/contrib/anu_lms/src/Form/LabelsForm.php on line 32 and exactly 2 expected in Drupal\Core\Form\ConfigFormBase->__construct() (line 44 of ........../core/lib/Drupal/Core/Form/ConfigFormBase.php).

Steps to reproduce

Proposed resolution

Fixed:
use Drupal\Core\Config\TypedConfigManagerInterface;


 /**
   * AdminToolbarToolsSettingsForm constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   The factory for configuration objects.
   * @param \Drupal\anu_lms\Settings $settings
   *   The Settings instance.
   */
  public function __construct(
       ConfigFactoryInterface $configFactory,
       TypedConfigManagerInterface $typedConfigManager,
       Settings $settings
   ) {
       parent::__construct($configFactory, $typedConfigManager);
       $this->settings = $settings;
   }

And fixed create()

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
       return new static(
           $container->get('config.factory'),
           $container->get('config.typed'), // Use 'config.typed' instead of 'module_handler'
           $container->get('anu_lms.settings')
       );
   }

This will fix the error that shows in 11.1.3

🐛 Bug report
Status

Active

Version

2.11

Component

Code

Created by

🇨🇦Canada netgeek123

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024