Fatal error when adding a module to the available target modules

Created on 14 October 2022, over 1 year ago
Updated 27 January 2023, over 1 year ago

Problem/Motivation

Adding a new target module produces this error, quite likely due to #3306016: Use strict typing in all PHP files (declare(strict_types=1);) β†’ no longer allowing PHP type coercion:

The website encountered an unexpected error. Please try again later.
TypeError: Drupal\config_enforce_devel\TargetModuleBuilder::setName(): Argument #1 ($name) must be of type Drupal\Core\StringTranslation\TranslatableMarkup, string given, called in E:\Web\Consensus\EnvisionRecycling\LogisticsApp\web\modules\contrib\config_enforce_devel\src\TargetModuleCollection.php on line 114 in Drupal\config_enforce_devel\TargetModuleBuilder->setName() (line 50 of modules\contrib\config_enforce_devel\src\TargetModuleBuilder.php).

Drupal\config_enforce_devel\TargetModuleBuilder->setName('Envision development') (Line: 114)
Drupal\config_enforce_devel\TargetModuleCollection->registerNewTargetModule('envision_devel') (Line: 36)
Drupal\config_enforce_devel\TargetModuleCollection->ensureTargetModulesAreRegistered(Array) (Line: 58)
Drupal\config_enforce_devel\Form\SettingsForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 592)
Drupal\Core\Form\FormBuilder->processForm('config_enforce_devel_settings', Array, Object) (Line: 320)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 159)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

  1. Navigate to /admin/config/development/config_enforce/settings
  2. Expand "Target modules"; select a module under "Available Options" and click the "+" arrow to add it to the "Selected Options" list.
  3. Click the "Save configuration" button; you should get the above error.

Proposed resolution

\Drupal\config_enforce_devel\TargetModuleCollection::registerNewTargetModule()
calls
\Drupal\config_enforce_devel\TargetModuleBuilder::setName()
with a string module name returned from the module handler service, but the
setName() parameter requires a
\Drupal\Core\StringTranslation\TranslatableMarkup object. Either we
wrap the module name in a translation like so:

->setName($this->t($this->getAllModules()[$module]))

or we expand the setName() parameter type hint to allow strings:
TranslatableMarkup|string

Remaining tasks

Make the above change.

User interface changes

None.

API changes

None.

Data model changes

None.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024