In Drupal 9, on the Hotjar settings form, no roles are listed in the "Roles" section and the following PHP warnings are shown:

Warning: array_map() expects parameter 1 to be a valid callback, class '\Drupal\Component\Utility\SafeMarkup' not found in Drupal\hotjar\Form\HotjarAdminSettingsForm->buildForm() (line 211 of ./web/modules/contrib/hotjar/src/Form/HotjarAdminSettingsForm.php)

Warning: count(): Parameter must be an array or an object that implements Countable in Drupal\Core\Render\Element\Checkboxes::processCheckboxes() (line 58 of ./web/core/lib/Drupal/Core/Render/Element/Checkboxes.php)

This is because \Drupal\Component\Utility\SafeMarkup was deprecated in Drupal 8 and removed in Drupal 9. I'd guess that the automated Deprecated Code Report missed this because it was in quoted text rather than straight code here:

$role_options = array_map(['\Drupal\Component\Utility\SafeMarkup', 'checkPlain'], user_role_names());

Per the link above, that can be replaced with a call to \Drupal\Component\Utility\Html::escape(). Patch to follow.

CommentFileSizeAuthor
#2 3155704-2.hotjar-d9-warnings.patch714 bytesjrb
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jrb created an issue. See original summary.

jrb’s picture

Patch to fix PHP warnings.

jrb’s picture

Status: Active » Needs review

  • tikaszvince committed a7a3350 on 8.x-2.x authored by jrb
    Issue #3155704 by jrb: PHP warnings in Drupal 9 due to deprecated...
tikaszvince’s picture

Status: Needs review » Fixed

Hi @jrb,

Thank you the contribution. This is part of the new 2.0-rc4 release of Hotar module.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.