Problem/Motivation
When I upgraded my project to Drupal 11.1.2 I got this error:
The website encountered an unexpected error. Try again later.
ArgumentCountError: Too few arguments to function Drupal\Core\Form\ConfigFormBase::__construct(), 1 passed in /var/www/html/web/modules/contrib/cookiepro_plus/src/Form/CookieProConfigFormBase.php on line 59 and exactly 2 expected in Drupal\Core\Form\ConfigFormBase->__construct() (line 44 of core/lib/Drupal/Core/Form/ConfigFormBase.php).
Drupal\cookiepro_plus\Form\CookieProConfigFormBase->__construct() (Line: 67)
Drupal\cookiepro_plus\Form\CookieProConfigFormBase::create() (Line: 36)
Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() (Line: 48)
Drupal\Core\Controller\HtmlFormController->getFormObject() (Line: 58)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 593)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 183)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 44)
Drupal\redirect_after_login\RedirectMiddleware->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 90)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 709)
Drupal\Core\DrupalKernel->handle() (Line: 19)
Steps to reproduce
- enable this module in D11.1.2
- try to visit admin/config/system/cookiepro-plus
Proposed resolution
Adjust cookiepro_plus/src/Form/CookieProConfigFormBase.php to pass a typedConfigManager to the parent constructor like this:
/**
* Constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typedConfigManager
* The typed config manager.
* @param \Drupal\cookiepro_plus\CookieProInterface $cookiePro
* The CookiePro service.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
*/
public function __construct(
ConfigFactoryInterface $config_factory,
TypedConfigManagerInterface $typedConfigManager,
protected CookieProInterface $cookiePro,
protected RendererInterface $renderer,
) {
parent::__construct($config_factory, $typedConfigManager);
$this->config = $this->config(static::CONFIG_KEY);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container): CookieProConfigFormBase {
return new static(
$container->get('config.factory'),
$container->get('config.typed'),
$container->get('cookiepro_plus'),
$container->get('renderer')
);
}
Remaining tasks
confirm bug, create patch or MR, review and test