Drupal Version
10.3.0
Domain module version
2.0.x-dev
Expected Behavior
The user Add/Edit page is loaded and Domain configurations can be configured.
Actual Behavior
Error on User add/edit page
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 79 of modules/contrib/domain/domain/src/DomainElementManager.php).

Steps to reproduce
- Install and enable the module
- Enable Domain Access & Domain content
- Configure the Domain
- Enable the Account form Domain fields
- Add/Edit a user
- Error will be shown
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | domain-type_error_count-3470873-6.patch | 995 bytes | seeduardo |
| Screenshot 2024-08-29 at 8.45.10 AM.png | 19.9 KB | joshua1234511 |
Issue fork domain-3470873
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 #3
joshua1234511Submitted a merge request. Ready for review.
Comment #4
dqdThe solution is somewhat doubling the condition check and could be more performant by using nested checks:
instead of
maybe like:
Comment #5
amir jamshidi commentedI made this condition like this
Comment #6
seeduardo commentedWhile I can confirm the code in #5 does work on D10.3, it is simply a repetition of what's in the merge request mentioned in #3. I agree with dqd in #4 that the change could be rewritten, but the code in that comment isn't quite right and would be a breaking change, so I've tweaked it in the patch attached here, which does work for me.
Comment #7
earthday47Here's my +1 comment - We are experiencing this issue and I can confirm that the patch in #6 resolves it.
Comment #8
therobyouknow commentedI also found #6 https://www.drupal.org/project/domain/issues/3470873#comment-15844907 to work, in that I don't now see that fatal error, the title of this issue "TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 79 of modules/contrib/domain/domain/src/DomainElementManager.php)". I needed to clear cache.
Thank you!
However, I get a warning on the node add/edit page: "Warning: Undefined array key "#options" in Drupal\domain\DomainElementManager->setFormOptions() (line 79 of modules/contrib/domain/domain/src/DomainElementManager.php)."
But I can get by. Hope for a fix for the warning (or even to help provide one), when I can.
Comment #9
guiu.rocafort.ferrerI managed to reproduce this error when using a "Autocomplete" or "Autocomplete (Tags style)" for the field "Domain Access" in the manage form display configuration for the content type.
Clearly the code does not contemplate the possibility of using those field widgets for this field, so the patches do not fix the root cause of the issue.
Comment #10
guiu.rocafort.ferrerComment #11
omahmAlso encountered this with the 'Chosen' module installed and set as the widget for Domain Access/Source.
Comment #13
guiu.rocafort.ferrerThe code now checks if the widget is of type checkbox/select, or if the widget is autocomplete.
If the code is checkbox/select, it does the same as before, but with an autocomplete field, it initializes the selection plugin and calls countReferenceableEntities() instead.
Regarding the 'Chosen' module, i have not tried it, but it should not throw an error and just not hide the field if there is no domain available.
Comment #14
the_g_bomb commentedMR !133 no longer applies to 2.0.x
Comment #15
divyansh.gupta commentedWorking on it.
Comment #16
divyansh.gupta commentedRebased the MR!133 against 2.0.x
Please review.
Comment #17
mably commented@divyansh.gupta did you have a look at your MR changes before setting it to "Needs review"?
Looks like it's rolling back all the recent updates to the dev branch...
Not sure the rebase was done properly.
Comment #18
divyansh.gupta commented@mably, Sorry but there was problem in previous rebase,
Rebased again properly,
Please review.
Comment #19
mably commentedThe Gitlab CI warnings and the failing tests need to be fixed
Comment #20
divyansh.gupta commentedSolved all PHPUnit errors and other Gitlab-Ci warnings,
Please review.
Comment #21
mably commentedSeems to work fine here. Thanks!
Comment #24
mably commented