Warning: count(): Parameter must be an array or an object that implements Countable when saving My Profile or Name and Address
Overview
Please describe your problem or bug in detail.
If you have already posted on https://civicrm.stackexchange.com or https://chat.civicrm.org, please include the link to that conversation.
Reproduction steps
- Click on My Account.
- Click on the Edit tab.
- Click on Name and Address tab.
- Get the warning message.
Current behaviour
What happens currently. Please provide error messages, screenshots or gifs (LICEcap, SilentCast) where appropriate.
Warning: count(): Parameter must be an array or an object that implements Countable in include() (line 15 of sites\default\files\civicrm\templates_c\en_GB\%%4D\4DC\4DC76B26%%body.tpl.php).
Note that this appears to be instance dependent. I had one instance that showed it, and one that did not.
Expected behaviour
What should happen. No error message. Environment information
- Browser: Edge_ but probably irrelevant.
- CiviCRM: 5.33.1
- PHP: 7.4_ but probably irrelevant.
- CMS: Drupal 9.1.2
- Database: MySQL 8.0
- Web Server: IIS 10
Comments
Anything else you would like the reviewer to note. This is not always reproducible. It can be cured by the following change to
<Drupal Root> web/custom-civicrm/templates/CRM/Form/body.tpl
+++ b/body
@@ -14,10 +14,7 @@
{if $form.hidden}
<div>{$form.hidden}</div>
{/if}
-{if (isset($form.errors))}
- {*
- If $form.errors isn't set, we get warning messages
- *}
+
{if ($snippet !== 'json') and !$suppressForm and count($form.errors) gt 0}
<div class="messages crm-error">
<i class="crm-i fa-exclamation-triangle crm-i-red" aria-hidden="true"></i>
@@ -33,7 +30,6 @@
</ul>
</div>
{/if}
-{/if}
{* Add all the form elements sent in by the hook *}
{if $beginHookFormElements}
If there has been an error, one would expect $form.errors to be set.