TypeError: Argument 1 passed to Civi\Core\Format::money() must be of the type string, null given
Overview
Free events are causing null to be passed to Civi\Core\Format::money(), which creates an error in Drupal when loading the Events Dashboard.
Reproduction steps
- Updated Drupal to 9.3.2 and CiviCRM to 5.46.beta1.
- Load Event Dashboard with any free Event
- Page returns the Drupal 'White Screen of Death'. Watchdog is showing the error "TypeError: Argument 1 passed to Civi\Core\Format::money() must be of the type string, null given"
Current behaviour
Full Error below:
TypeError: Argument 1 passed to Civi\Core\Format::money() must be of the type string, null given, called in /vendor/civicrm/civicrm-core/CRM/Core/Smarty/plugins/modifier.crmMoney.php on line 32 in Civi\Core\Format->money() (line 36 of /public_html/vendor/civicrm/civicrm-core/Civi/Core/Format.php)
#0 /vendor/civicrm/civicrm-core/CRM/Core/Smarty/plugins/modifier.crmMoney.php(32): Civi\Core\Format->money(NULL, 'USD')
#1 /public_html/sites/default/files/civicrm/templates_c/en_US/%%FE/FEB/FEB92208%%Selector.tpl.php(21): smarty_modifier_crmMoney(NULL, 'USD')
#2 /public_html/vendor/civicrm/civicrm-packages/Smarty/Smarty.class.php(1914): include('...')
#3 /public_html/sites/default/files/civicrm/templates_c/en_US/%%1B/1B4/1B447EC5%%DashBoard.tpl.php(190): Smarty->_smarty_include(Array)
#4 /public_html/vendor/civicrm/civicrm-packages/Smarty/Smarty.class.php(1914): include('...')
#5 /public_html/sites/default/files/civicrm/templates_c/en_US/%%0C/0CB/0CBEC124%%default.tpl.php(19): Smarty->_smarty_include(Array)
#6 /public_html/vendor/civicrm/civicrm-packages/Smarty/Smarty.class.php(1914): include('...')
#7 /public_html/sites/default/files/civicrm/templates_c/en_US/%%F7/F77/F77C7890%%CMSPrint.tpl.php(51): Smarty->_smarty_include(Array)
#8 /public_html/vendor/civicrm/civicrm-packages/Smarty/Smarty.class.php(1914): include('...')
#9 /public_html/sites/default/files/civicrm/templates_c/en_US/%%2B/2BD/2BD99720%%drupal8.tpl.php(6): Smarty->_smarty_include(Array)
#10 /public_html/vendor/civicrm/civicrm-packages/Smarty/Smarty.class.php(1273): include('...')
#11 /public_html/vendor/civicrm/civicrm-core/CRM/Core/Smarty.php(194): Smarty->fetch('CRM/common/drup...', NULL, NULL, false)
#12 /public_html/vendor/civicrm/civicrm-core/CRM/Core/Page.php(244): CRM_Core_Smarty->fetch('CRM/common/drup...')
#13 /public_html/vendor/civicrm/civicrm-core/CRM/Event/Page/DashBoard.php(65): CRM_Core_Page->run()
#14 /public_html/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(319): CRM_Event_Page_DashBoard->run(Array, NULL)
#15 /public_html/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(69): CRM_Core_Invoke::runItem(Array)
#16 /public_html/vendor/civicrm/civicrm-core/CRM/Core/Invoke.php(36): CRM_Core_Invoke::_invoke(Array)
#17 /public_html/modules/contrib/civicrm/src/Civicrm.php(88): CRM_Core_Invoke::invoke(Array)
#18 /public_html/modules/contrib/civicrm/src/Controller/CivicrmController.php(80): Drupal\civicrm\Civicrm->invoke(Array)
#19 [internal function]: Drupal\civicrm\Controller\CivicrmController->main(Array, '')
#20 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#21 /public_html/core/lib/Drupal/Core/Render/Renderer.php(564): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#22 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#23 /public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#24 /public_html/vendor/symfony/http-kernel/HttpKernel.php(158): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#25 /public_html/vendor/symfony/http-kernel/HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#26 /public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#32 /public_html/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#33 /public_html/core/lib/Drupal/Core/DrupalKernel.php(708): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#34 /public_html/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#35 {main}
.
Expected behaviour
Events page should load, but Drupal displays WSOD.
Environment information
- CiviCRM: 5.46.beta1
- PHP: 7.4
- CMS: Drupal 9.3.2
Comments
I created a temporary fix, which might not be the best solution. I modified /vendor/civicrm/civicrm-core/CRM/Core/Smarty/plugins/modifier.crmMoney.php for the time being:
function smarty_modifier_crmMoney($amount, ?string $currency = NULL): string {
if ($amount == NULL)
{
$amount = '0';
}
return Civi::format()->money($amount, $currency);
}
Now free events are displaying $0.00 and the Events page loads again. I'm pretty new to CiviCRM, so please let me know if I can provide any other information.