Unverified Commit 2aa1f42b authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3550174 by thejimbirch, phenaproxima, b_sharpe: TypeError in...

Issue #3550174 by thejimbirch, phenaproxima, b_sharpe: TypeError in CreateForEachBundle when processing config with integer or boolean schema types

(cherry picked from commit f4b0ecfb)
parent d5b74381
Loading
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -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;
  }

+7 −0
Original line number Diff line number Diff line
@@ -196,10 +196,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());