willianmano / moodle-theme_moove

A Moodle Boost child theme
GNU General Public License v3.0
171 stars 157 forks source link

generalexceptionmessage on the front page when misusing FAQ #411

Closed robelko closed 21 hours ago

robelko commented 1 year ago

Error Exception - count(): Argument #1 ($value) must be of type Countable|array, null given

Debug info: Error code: generalexceptionmessage

Stack trace: line 228 of /theme/moove/classes/util/settings.php: TypeError thrown line 228 of /theme/moove/classes/util/settings.php: call to count() line 128 of /theme/moove/classes/util/settings.php: call to theme_moove\util\settings->faq() line 125 of /theme/moove/layout/frontpage.php: call to theme_moove\util\settings->frontpage() line 1473 of /lib/outputrenderers.php: call to include() line 1399 of /lib/outputrenderers.php: call to core_renderer->render_page_layout() line 116 of /index.php: call to core_renderer->header()

The error is triggered if the number of FAQ questions on the frontpage is set to let's say 3 but no questions/answers are provided. Yes, stupid mistake of a local Moodle manager. Unfortunately, it renders the site inaccessible for normal users since the error is displayed instead of the frontpage.

The offending code is: if (count($templatecontext['faq'])) { $templatecontext['faqenabled'] = true; }

A solution could be to use if (!empty($templatecontext['faq'])) { $templatecontext['faqenabled'] = true; }

jtentis commented 7 months ago

Thanks a lot for that tip, It was exactly what was happening to me!