fix: #3586043 Coerce array dynamical token values to string in applyTokens()

Fixes #3586043.

AiAgentEntityWrapper::applyTokens() merges the dynamical $this->tokens into the data passed to Token::replacePlain(). When a token value is an array it reaches str_replace() in Token::doReplace() and logs "Array to string conversion" on every agent run. This coerces array values to a string (scalars joined) before replacePlain(), so no array reaches str_replace().

Tested on Drupal 11.3, ai_agents 1.3.x: warning eliminated, agent runs and prompt token replacement unaffected.


AI usage disclosure (per https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquette/policy-on-the-use-of-ai-when-contributing-to-drupal): AI-Generated: Yes — the patch and this writeup were drafted with AI (Claude) assistance. I, Rajab Natshah, reviewed, tested, and take full responsibility for the correctness, security, and GPL compatibility of this change.

Checkpoints:

  • File an issue
  • Addition/Change/Update/Fix
  • Testing to ensure no regression
  • Automated unit testing coverage
  • Automated functional testing coverage
  • UX/UI designer responsibilities
  • Readability
  • Accessibility
  • Performance
  • Security
  • Documentation
  • Reviewed by a human
  • Code review by maintainers
  • Full testing and approval
  • Credit contributors
  • Review with the product owner
  • Release notes snippet
  • Release

Merge request reports

Loading