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

Issue fork tac_lite-3307744

Command icon 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

Kris77 created an issue. See original summary.

kris77’s picture

Title: TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 40 of /Users/crescenzovelleca/Sites/EduItaliaNew/web/modules/contrib/tac_lite/src/Form/SchemeForm.php) » 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)
rik.scholten’s picture

Status: Active » Needs review
StatusFileSize
new625 bytes

Instead of casting to array I added a fallback. This way you don't have to convert to an array (solution stays the same).

kris77’s picture

Thank you so much @rik.scholten

Your patch works fine for me. Drupal 9.45 and PHP 8.1

rik.scholten’s picture

StatusFileSize
new537 bytes

After 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!

kris77’s picture

Thanks @rik.scholten

liam morland’s picture

Version: 8.x-1.6 » 8.x-1.x-dev

This fix is a start and would be a good idea in any case.

I am seeing this after having enabled tac_lite but 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.

msankhala’s picture

StatusFileSize
new146.68 KB

Patch #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.

tvalimaa’s picture

Patch 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.

jannakha’s picture

Status: Needs review » Reviewed & tested by the community

thank you for your contribution.
fix works.

liam morland’s picture

I created a merge request with the patch in #5.

vladimiraus’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Assigned: kris77 » Unassigned
Status: Reviewed & tested by the community » Fixed

Thanks for your contributions. Committed.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • vladimiraus committed 03464eda on 2.0.x
    feat: #3307744 TypeError: count(): Argument #1 () must be of type...

  • vladimiraus committed a3b3147b on 8.x-1.x
    feat: #3307744 TypeError: count(): Argument #1 () must be of type...

Status: Fixed » Closed (fixed)

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