Issue #2718717 by damiankloip: Assertion error when paging a view using an entity autocomplete exposed filter

8.2.x
Nathaniel Catchpole 2016-06-06 11:20:40 +01:00
parent 4ad7ddb35a
commit 3f52754e42
2 changed files with 12 additions and 1 deletions

View File

@ -373,7 +373,8 @@ abstract class PluginBase extends ComponentPluginBase implements ContainerFactor
assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $top) === 1', 'Tokens need to be valid Twig variables.'); assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $top) === 1', 'Tokens need to be valid Twig variables.');
$token_array = array(array_pop($parts) => $replacement); $token_array = array(array_pop($parts) => $replacement);
foreach (array_reverse($parts) as $key) { foreach (array_reverse($parts) as $key) {
assert('preg_match(\'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/\', $key) === 1', 'Tokens need to be valid Twig variables.'); // The key could also be numeric (array index) so allow that.
assert('is_numeric($key) || (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); $token_array = array($key => $token_array);
} }
if (!isset($twig_tokens[$top])) { if (!isset($twig_tokens[$top])) {

View File

@ -55,6 +55,16 @@ class PluginBaseTest extends KernelTestBase {
}); });
$this->assertIdentical($result, 'first comes before second'); $this->assertIdentical($result, 'first comes before second');
// Test tokens with numeric indexes.
$text = '{{ argument.0.first }} comes before {{ argument.1.second }}';
$tokens = ['{{ argument.0.first }}' => 'first', '{{ argument.1.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');
} }
/** /**