Problem/Motivation
In the setting page I have this error when click on "Scheme":
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 40 of /web/modules/contrib/tac_lite/src/Form/SchemeForm.php)
Proposed resolution
In line 40 of modules/contrib/tac_lite/src/Form/SchemeForm.php replacement this code:
if (count($vids)) {
with this:
if (count((array)$vids)) {
Works for me with Drupal 9.4.5 and PHP 8.1
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Screenshot 2023-08-29 at 12.25.08 AM.png | 146.68 KB | msankhala |
| #5 | tac_lite-3307744-5.patch | 537 bytes | rik.scholten |
Issue fork tac_lite-3307744
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
kris77 commentedComment #3
rik.scholtenInstead of casting to array I added a fallback. This way you don't have to convert to an array (solution stays the same).
Comment #4
kris77 commentedThank you so much @rik.scholten
Your patch works fine for me. Drupal 9.45 and PHP 8.1
Comment #5
rik.scholtenAfter reviewing this code with a co-worker we realized there was a better solution. This should work the same, without the use of count() and without setting a fallback.
if $vids = NULL it skips the if statement.
if $vids = [] it skips the if statement.
if $vids contains items it continues inside the if statement
I don't know how I didnt see this earlier but this should be the best solution!
Comment #6
kris77 commentedThanks @rik.scholten
Comment #7
liam morlandThis fix is a start and would be a good idea in any case.
I am seeing this after having enabled
tac_litebut not doing any config. If there are no schemes configured, it should not show the "Scheme 1" tab at all and visiting the URL should give a 404.Comment #8
msankhala commentedPatch #5 works fine. If there are no schemes configured then the "Scheme 1" tab shows proper instructions:
First, select one or more vocabularies on the settings tab. Then, return to this page to complete configuration.Which I believe is good enough, instead of hiding the "Scheme 1" entirely until you select the vocabulary.
Comment #9
tvalimaa commentedPatch works with tac_lite (2.0.1).
Can this be put forward because without this patch clean install tac_lite will always gives fatal error and this issue is old.
Comment #10
jannakha commentedthank you for your contribution.
fix works.
Comment #12
liam morlandI created a merge request with the patch in #5.
Comment #13
vladimirausThanks for your contributions. Committed.