Problem/Motivation
When using recipe config actions that utilize `CreateForEachBundle` (such as `createForEachIfNotExists`, `createForEach`, or any action using wildcard config names like `node.type.*`), a TypeError occurs if the configuration being processed contains fields defined as `integer` or `boolean` types in the config schema.
Error:
TypeError: str_replace(): Argument #3 ($subject) must be of type array|string, int given
in CreateForEachBundle.php on line 128
Steps to reproduce
1. Create a Drupal recipe with a `createForEachIfNotExists` action targeting a wildcard pattern (e.g., `node.type.*`)
2. Include configuration that references entities with integer or boolean schema types (e.g., `ai_automator` config with `weight: 100` and `edit_mode: false`)
3. Apply the recipe using `php web/core/scripts/drupal recipe recipes/your_recipe`
4. Observe TypeError
Root Cause:
1. Config Schema Typing: When configuration is loaded and validated against config schemas (e.g., `ai_automators.schema.yml`), fields typed as `integer` or `boolean` are converted from YAML to native PHP integers and booleans. This is correct and expected behavior.
2. Array Key Processing: During the schema validation process, if configuration data structures contain numeric keys, these keys may be represented as PHP integers (depending on how YAML is parsed and validated).
3. Missing Type Check: The `CreateForEachBundle::replacePlaceholders()` method attempts to perform `str_replace()` on ALL array keys without first checking if the key is a string. When it encounters an integer key, `str_replace()` throws a TypeError because it only accepts string or array types for its third argument.
Proposed resolution
Thanks to guidance from @phenaproxima,
Wrap the str_replace() call in an is_string() check. Only perform placeholder replacement on string keys and values, since non-string types (integers, booleans, floats, null) cannot contain placeholders anyway.
Remaining tasks
MR to follow
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3550174
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
thejimbirch commentedComment #3
thejimbirch commentedComment #5
thejimbirch commentedMR added.
Comment #6
phenaproximaNo objections to that fix. Needs a test though!
Comment #7
thejimbirch commentedCalling all testers! That is beyond my skillset.
Comment #8
b_sharpe commentedComment #9
b_sharpe commentedUpdated the existing test as it's really the same thing, just we didn't have non-string values in it before. Simplified the method a little as well to make more readable.
Comment #10
phenaproximaCouple minor points about comments, otherwise RTBC.
Comment #11
b_sharpe commentedComment #12
thejimbirch commentedSince this is a bug in the existing code base, would it be possible to bring this down to 10.x also?
We're needing this in the AI initiative SEO Optimizer recipe.
Comment #13
phenaproximaI'm not sure the %bundle replacement in keys even exists in 10.x at all, but if it does, then IMHO it should be backported.
Comment #14
phenaproximaOne suggestion for clarity, RTBC otherwise.
Comment #15
alexpottCommitted and pushed f4b0ecfb98d to 11.x and 2aa1f42b032 to 11.2.x. Thanks!