Loading core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/CreateForEachBundle.php +13 −8 Original line number Diff line number Diff line Loading @@ -118,20 +118,25 @@ private static function replacePlaceholders(mixed $data, array $replacements): m assert(array_key_exists(static::BUNDLE_PLACEHOLDER, $replacements)); if (is_string($data)) { $data = str_replace(array_keys($replacements), $replacements, $data); return str_replace(array_keys($replacements), $replacements, $data); } elseif (is_array($data)) { if (!is_array($data)) { return $data; } foreach ($data as $old_key => $value) { $value = static::replacePlaceholders($value, $replacements); // Only replace the `%bundle` placeholder in array keys. // Non-string keys cannot contain placeholders. if (is_string($old_key)) { $new_key = str_replace(static::BUNDLE_PLACEHOLDER, $replacements[static::BUNDLE_PLACEHOLDER], $old_key); if ($old_key !== $new_key) { unset($data[$old_key]); } $data[$new_key] = $value; } } return $data; } Loading core/tests/Drupal/KernelTests/Core/Recipe/WildcardConfigActionsTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -199,10 +199,17 @@ public function testCreateForEachWithLabel(): void { $this->enableModules(['image']); // We should be able to use the `%label` placeholder. // Also ensure nested and non-string keys/values are handled correctly. $this->container->get('plugin.manager.config_action') ->applyAction('createForEach', 'node.type.*', [ 'image.style.node_%bundle_big' => [ 'label' => 'Big image for %label content', 'effects' => [ [ 'id' => 'image_scale', 'weight' => 10, ], ], ], ]); $this->assertSame('Big image for Type A content', ImageStyle::load('node_one_big')?->label()); Loading Loading
core/lib/Drupal/Core/Config/Action/Plugin/ConfigAction/CreateForEachBundle.php +13 −8 Original line number Diff line number Diff line Loading @@ -118,20 +118,25 @@ private static function replacePlaceholders(mixed $data, array $replacements): m assert(array_key_exists(static::BUNDLE_PLACEHOLDER, $replacements)); if (is_string($data)) { $data = str_replace(array_keys($replacements), $replacements, $data); return str_replace(array_keys($replacements), $replacements, $data); } elseif (is_array($data)) { if (!is_array($data)) { return $data; } foreach ($data as $old_key => $value) { $value = static::replacePlaceholders($value, $replacements); // Only replace the `%bundle` placeholder in array keys. // Non-string keys cannot contain placeholders. if (is_string($old_key)) { $new_key = str_replace(static::BUNDLE_PLACEHOLDER, $replacements[static::BUNDLE_PLACEHOLDER], $old_key); if ($old_key !== $new_key) { unset($data[$old_key]); } $data[$new_key] = $value; } } return $data; } Loading
core/tests/Drupal/KernelTests/Core/Recipe/WildcardConfigActionsTest.php +7 −0 Original line number Diff line number Diff line Loading @@ -199,10 +199,17 @@ public function testCreateForEachWithLabel(): void { $this->enableModules(['image']); // We should be able to use the `%label` placeholder. // Also ensure nested and non-string keys/values are handled correctly. $this->container->get('plugin.manager.config_action') ->applyAction('createForEach', 'node.type.*', [ 'image.style.node_%bundle_big' => [ 'label' => 'Big image for %label content', 'effects' => [ [ 'id' => 'image_scale', 'weight' => 10, ], ], ], ]); $this->assertSame('Big image for Type A content', ImageStyle::load('node_one_big')?->label()); Loading