ArgumentCountError: Too few arguments to function Drupal\system\Controller\SystemController::__construct()

Created on 14 December 2023, about 1 year ago
Updated 20 December 2023, 12 months ago

Problem:

ArgumentCountError: Too few arguments to function Drupal\system\Controller\SystemController::__construct(), 5 passed in /app/docroot/modules/contrib/theme_permission/src/Controller/AccessController.php on line 63 and exactly 6 expected in Drupal\system\Controller\SystemController->__construct() (line 86 of core/modules/system/src/Controller/SystemController.php).
Drupal\theme_permission\Controller\AccessController->__construct(Object, Object, Object, Object, Object, Object, Object) (Line: 79)
Drupal\theme_permission\Controller\AccessController::create(Object) (Line: 28)
Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition('\Drupal\theme_permission\Controller\AccessController') (Line: 116)
Drupal\Core\Controller\ControllerResolver->createController('\Drupal\theme_permission\Controller\AccessController::access') (Line: 68)
Drupal\Core\Controller\ControllerResolver->getControllerFromDefinition('\Drupal\theme_permission\Controller\AccessController::access') (Line: 65)
Drupal\Core\Access\CustomAccessCheck->access(Object, Object, Object)
call_user_func_array(Array, Array) (Line: 160)

Steps to reproduce

I was trying to open the admin/appearances section and facing this above mentioned Issue.
To reproduce issue, you need to have up running Drupal 10.x site and when you try to open appearances section or admin/structure/block then you will see this error.

Proposed resolution

As per my investigation, i came to this conclusion that the previous core version had the same thing but it was handled by the validation to ignore the error. It was by default taking value if the argument is not passed by the caller.

Drupal 9.x branch code:

  public function __construct(SystemManager $systemManager, ThemeAccessCheck $theme_access, FormBuilderInterface $form_builder, ThemeHandlerInterface $theme_handler, MenuLinkTreeInterface $menu_link_tree, ModuleExtensionList $module_extension_list = NULL) {
    $this->systemManager = $systemManager;
    $this->themeAccess = $theme_access;
    $this->formBuilder = $form_builder;
    $this->themeHandler = $theme_handler;
    $this->menuLinkTree = $menu_link_tree;
    if ($module_extension_list === NULL) {
      @trigger_error('The extension.list.module service must be passed to ' . __NAMESPACE__ . '\SystemController::__construct. It was added in Drupal 8.9.0 and will be required before Drupal 10.0.0.', E_USER_DEPRECATED);
      $module_extension_list = \Drupal::service('extension.list.module');
    }
    $this->moduleExtensionList = $module_extension_list;
  }

Drupal 10.x branch code:

public function __construct(SystemManager $systemManager, ThemeAccessCheck $theme_access, FormBuilderInterface $form_builder, ThemeHandlerInterface $theme_handler, MenuLinkTreeInterface $menu_link_tree, ModuleExtensionList $module_extension_list) {
    $this->systemManager = $systemManager;
    $this->themeAccess = $theme_access;
    $this->formBuilder = $form_builder;
    $this->themeHandler = $theme_handler;
    $this->menuLinkTree = $menu_link_tree;
    $this->moduleExtensionList = $module_extension_list;
  }

Now, it's clearly visible that either you should pass the argument during this constructor call or you have to add this validation back to the Drupal 10.x branch as a fix of this issue.

But, what i feel is that the go with the flow which previous version was following. That's why i am adding this validation back rather add argument to the function call.

๐Ÿ› Bug report
Status

Needs review

Version

2.0

Component
Themeย  โ†’

Last updated about 4 hours ago

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

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

Merge Requests

Comments & Activities

  • Issue created by @smitghelani
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

    As part of fix which i have mentioned above inside the description, I am recommending this patch as the fix for the error. It's providing the fix for the issue which I am getting and compatible with Drupal core 10.x branch.

  • Status changed to Postponed: needs info about 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam

    The fault seems to lie with AccessController in the theme_permission module that is making this call, that needs to be updated to use the correct constructor arguments.

    If you switch off that module, does the error go away? If so, please open an issue for that module.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

    I missed the 1 thing inside the #2 patch, ModuleExtensionList $module_extension_list = NULL this parameter of function was missing to adding new patch.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

    @lendude Thanks for your response,

    I want to know more about the reason behind removing the validation which i have mentioned here inside description.

    If you visit this file of drupal 9.5.x branch https://git.drupalcode.org/project/drupal/-/blob/9.5.x/core/modules/syst... which has constructor with validations and inside drupal 10.0.x and above branches has missed this things. If i again do the same validation i am not seeing any issue from my side. this patch is doing the same thing for me.

    If you can guide me more about this why the things got changed inside the latest version. I can get more clarity on this issue.

  • Status changed to Active about 1 year ago
  • ๐Ÿ‡ณ๐Ÿ‡ฑNetherlands Lendude Amsterdam

    It's a deprecation message.

    @trigger_error('The extension.list.module service must be passed to ' . __NAMESPACE__ . '\SystemController::__construct. It was added in Drupal 8.9.0 and will be required before Drupal 10.0.0.', E_USER_DEPRECATED);

    Not passing extension.list.module to the constructor is deprecated, so like the message says, before to mark your module ready for D10, you need to pass this to the constructor if you are extending SystemController, or it will break....which it did

    So that module probably extends SystemController (I didn't check) and they need to update their code, so let's move the issue to that queue

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 8
    last update about 1 year ago
    Patch Failed to Apply
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia smitghelani Surat, Gujarat

    I have created another patch to fix this issue from the theme_permission module side, tested locally and it's working for my requirement. It's working for the version below mentioned requirements:

    theme_permission: 2.0.0
    Drupal core: 10.x

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 5.6
    last update about 1 year ago
    Patch Failed to Apply
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 8
    last update about 1 year ago
    Patch Failed to Apply
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    chetan 11 โ†’ made their first commit to this issueโ€™s fork.

  • Merge request !8fixed โ†’ (Open) created by chetan 11
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 10.1.4 + Environment: PHP 7.4 & MySQL 8
    last update 12 months ago
    Composer require failure
  • Issue was unassigned.
  • Status changed to Needs review 12 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chetan 11

    Please check the above solution in MR.

Production build 0.71.5 2024