Problem
Brief:
TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 427 of /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php) #0 /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php(427): count(NULL)\n#1
Full Error:
[Wed, 07/13/2022 - 15:18 EDT] [Error] [php] [client: ::1, admin] TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in count() (line 427 of /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php) #0 /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php(427): count(NULL)\n#1 /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php(224): Drupal\entity_embed\Form\EntityEmbedDialog->buildEmbedStep(Array, Object(Drupal\Core\Form\FormState))\n#2 [internal function]: Drupal\entity_embed\Form\EntityEmbedDialog->buildForm(Array, Object(Drupal\Core\Form\FormState), Object(Drupal\editor\Entity\Editor), Object(Drupal\embed\Entity\EmbedButton))\n#3 /htdocs/drupal-project/core/lib/Drupal/Core/Form/FormBuilder.php(531): call_user_func_array(Array, Array)\n#4 /htdocs/drupal-project/core/lib/Drupal/Core/Form/FormBuilder.php(370): Drupal\Core\Form\FormBuilder->retrieveForm('entity_embed_di...', Object(Drupal\Core\Form\FormState))\n#5 /htdocs/drupal-project/modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php(757): Drupal\Core\Form\FormBuilder->rebuildForm('entity_embed_di...', Object(Drupal\Core\Form\FormState), Array)\n#6 [internal function]: Drupal\entity_embed\Form\EntityEmbedDialog->submitSelectStep(Array, Object(Drupal\Core\Form\FormState), Object(Symfony\Component\HttpFoundation\Request))\n#7 /htdocs/drupal-project/core/lib/Drupal/Core/Form/FormAjaxResponseBuilder.php(69): call_user_func_array(Array, Array)\n#8 /htdocs/drupal-project/core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php(109): Drupal\Core\Form\FormAjaxResponseBuilder->buildResponse(Object(Symfony\Component\HttpFoundation\Request), Array, Object(Drupal\Core\Form\FormState), Array)\n#9 [internal function]: Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber->onException(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))\n#10 /htdocs/drupal-project/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))\n#11 /htdocs/drupal-project/vendor/symfony/http-kernel/HttpKernel.php(219): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ExceptionEvent), 'kernel.exceptio...')\n#12 /htdocs/drupal-project/vendor/symfony/http-kernel/HttpKernel.php(91): Symfony\Component\HttpKernel\HttpKernel->handleThrowable(Object(Drupal\Core\Form\FormAjaxException), Object(Symfony\Component\HttpFoundation\Request), 1)\n#13 /htdocs/drupal-project/modules/contrib/force_password_change/src/Service/ForcePasswordChangeRedirectMiddleware.php(42): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#14 /htdocs/drupal-project/modules/contrib/simple_oauth/src/HttpMiddleware/BasicAuthSwap.php(67): Drupal\force_password_change\Service\ForcePasswordChangeRedirectMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#15 /htdocs/drupal-project/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#16 /htdocs/drupal-project/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#17 /htdocs/drupal-project/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#18 /htdocs/drupal-project/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#19 /htdocs/drupal-project/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#20 /htdocs/drupal-project/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#21 /htdocs/drupal-project/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#22 /htdocs/drupal-project/core/lib/Drupal/Core/DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)\n#23 /htdocs/drupal-project/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))\n#24 {main}.
PHP 8.1.0
entity_embed version "^1.2"
core version 9.4.1
db postgres
Triggered when selecting an item to embed
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3295818-count-array-php-8-syntax-update-2.patch | 1.37 KB | jakegibs617 |
| #3 | 3295818-count-array-php-8-syntax-update.patch | 3.09 KB | jakegibs617 |
Issue fork entity_embed-3295818
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
jakegibs617 commentedseems like we just need to add count((array)
modules/contrib/entity_embed/src/Form/EntityEmbedDialog.php
- if (count( $entity_element['data-entity-ids']) > 0) {
+ if (count((array) $entity_element['data-entity-ids']) > 0) {
Comment #3
jakegibs617 commentedComment #4
wxman commentedI've been having the same problem. Had to switch PHP back to 8.0.x
Comment #5
dave reidCan we please target the specific instance of count() that is causing the error? This just blindly adds array casting to things that definitely do not need them.
Comment #6
jakegibs617 commentedFair point @Dave Reid This isolates it to what fixed it for me
Comment #7
anybodyComment #8
anybodyWouldn't a simple
!is_empty($entity_element['data-entity-ids'])check do better here?It doesn't require the casting and is faster.
Comment #10
anybodyI prepared a MR based on my suggestion in #8.
Comment #12
baluertlCannot reproduce on Core 9.5.11 + PHP 8.1.28 + entity_embed 8.x-1.x-dev: inserting a node into another one through WYSIWYG works as expected. As the suggested fix is beneficial for better stability, I would mark this ticket RTBC but tests are failing on the MR, so let's wait them getting into HEAD, then get back to here again.
Comment #13
baluertl