Commit aca6ac9c authored by Jess's avatar Jess
Browse files

Issue #2591125 by Berdir, Jaesin: Only the last views argument token works

parent 8770d0c7
Loading
Loading
Loading
Loading
+4 −1
Changes for core/modules/views/src/Plugin/views/PluginBase.php: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -382,7 +382,10 @@ protected function viewsTokenReplace($text, $tokens) {
          assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $key) === 1', 'Tokens need to be valid Twig variables.');
          $token_array = array($key => $token_array);
        }
        $twig_tokens[$top] = $token_array;
        if (!isset($twig_tokens[$top])) {
          $twig_tokens[$top] = [];
        }
        $twig_tokens[$top] += $token_array;
      }
    }

+14 −0
Changes for core/modules/views/src/Tests/Plugin/PluginBaseTest.php: 14 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -43,6 +43,20 @@ public function testViewsTokenReplace() {
    $this->assertIdentical($result, 'en means English');
  }

  /**
   * Test that the token replacement in views works correctly with dots.
   */
  public function testViewsTokenReplaceWithDots() {
    $text = '{{ argument.first }} comes before {{ argument.second }}';
    $tokens = ['{{ argument.first }}' => 'first', '{{ argument.second }}' => 'second'];

    $result = \Drupal::service('renderer')->executeInRenderContext(new RenderContext(), function () use ($text, $tokens) {
      return $this->testPluginBase->viewsTokenReplace($text, $tokens);
    });

    $this->assertIdentical($result, 'first comes before second');
  }

  /**
   * Tests viewsTokenReplace without any twig tokens.
   */