Warning: foreach() argument must be of type array|object, string given in Drupal\ai_auto_reference\Form\AutoReferenceApplyForm->submitForm()

Created on 30 July 2025, 2 months ago

Problem/Motivation

I tried to generate tags with a valid OpenAI key and when I got no suggestions this was logged:

Warning: foreach() argument must be of type array|object, string given in Drupal\ai_auto_reference\Form\AutoReferenceApplyForm->submitForm() (line 178 of /app/web/modules/contrib/ai_auto_reference/src/Form/AutoReferenceApplyForm.php)
#0 /app/web/core/includes/bootstrap.inc(104): _drupal_error_handler_real(2, 'foreach() argum...', '/app/web/module...', 178)
#1 /app/web/modules/contrib/ai_auto_reference/src/Form/AutoReferenceApplyForm.php(178): _drupal_error_handler(2, 'foreach() argum...', '/app/web/module...', 178)
#2 [internal function]: Drupal\ai_auto_reference\Form\AutoReferenceApplyForm->submitForm(Array, Object(Drupal\Core\Form\FormState))
#3 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(105): call_user_func_array(Array, Array)
#4 /app/web/core/lib/Drupal/Core/Form/FormSubmitter.php(43): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object(Drupal\Core\Form\FormState))
#5 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(589): Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object(Drupal\Core\Form\FormState))
#6 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(321): Drupal\Core\Form\FormBuilder->processForm('ai_reference_ap...', Array, Object(Drupal\Core\Form\FormState))
#7 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(219): Drupal\Core\Form\FormBuilder->buildForm('Drupal\\ai_auto_...', Object(Drupal\Core\Form\FormState))
#8 /app/web/modules/contrib/ai_auto_reference/ai_auto_reference.module(28): Drupal\Core\Form\FormBuilder->getForm('Drupal\\ai_auto_...', Object(Drupal\node\Entity\Node), Array)
#9 /app/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(472): ai_auto_reference_form_node_form_alter(Array, Object(Drupal\Core\Form\FormState), 'node_article_ed...')
#10 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(838): Drupal\Core\Extension\ModuleHandler->alter(Array, Array, Object(Drupal\Core\Form\FormState), 'node_article_ed...')
#11 /app/web/core/lib/Drupal/Core/Form/FormBuilder.php(280): Drupal\Core\Form\FormBuilder->prepareForm('node_article_ed...', Array, Object(Drupal\Core\Form\FormState))
#12 /app/web/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm(Object(Drupal\node\Form\NodeForm), Object(Drupal\Core\Form\FormState))
#13 [internal function]: Drupal\Core\Controller\FormController->getContentResult(Object(Symfony\Component\HttpFoundation\Request), Object(Drupal\Core\Routing\RouteMatch))
#14 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
#15 /app/web/core/lib/Drupal/Core/Render/Renderer.php(622): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::wrapControllerExecutionInRenderContext():121}()
#16 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
#17 /app/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
#18 /app/vendor/symfony/http-kernel/HttpKernel.php(183): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->{closure:Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber::onController():96}()
#19 /app/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#20 /app/web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#21 /app/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#22 /app/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#23 /app/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#24 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#25 /app/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#26 /app/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#27 /app/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#28 /app/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(53): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#29 /app/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#30 /app/web/core/lib/Drupal/Core/DrupalKernel.php(715): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#31 /app/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#32 {main}

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇸🇰Slovakia kaszarobert

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @kaszarobert
  • First commit to issue fork.
  • @ushma opened merge request.
  • 🇮🇳India ushma

    Please review MR. Also attaching patch for the same.
    This patch prevents the foreach() warning by ensuring loops only run on arrays in the submit handler. It also skips saving the node if no changes were made

  • Status changed to Fixed 6 days ago
Production build 0.71.5 2024