Skip to content
Snippets Groups Projects
Commit e7f564fc authored by mxh's avatar mxh
Browse files

Issue #3250451 by mxh: mustache_magic: Using Tokens and a URL at the same time...

Issue #3250451 by mxh: mustache_magic: Using Tokens and a URL at the same time might conflict in variable resolution
parent 6ba0bbdb
No related branches found
Tags 4.4.0
No related merge requests found
......@@ -347,8 +347,7 @@ class Sync extends MustacheMagic {
$server_side_render = $build->toRenderArray();
$server_side_render['#sync'] = [];
// @todo Consider a way to support both Tokens and URLs in one template.
if (empty($url) && !empty($this->element['#with_tokens'])) {
if (!empty($this->element['#with_tokens'])) {
$server_side_render['#with_tokens'] = $this->element['#with_tokens'];
/** @var \Drupal\mustache\MustacheTokenProcessor $token_processor */
$token_processor = \Drupal::service('mustache.token_processor');
......
......@@ -179,12 +179,21 @@ class Mustache extends RenderElement {
if ($received === FALSE) {
// Something went wrong, thus make this render array uncacheable.
$element['#cache']['max-age'] = 0;
$element['#received'] = FALSE;
if (!isset($data)) {
// Return an empty element when there is nothing available.
return static::emptyElement();
}
}
$element['#received'] = TRUE;
if ($data instanceof IterableMarkup) {
if (empty($received) && !isset($data[0])) {
// By setting an empty child element with a numeric key, the data
// will be treated as non-associative array. Loops will then behave
// like the list would be empty, and will not include any associative
// keys, e.g. provided by Tokens.
$data[0] = IterableMarkup::create([], NULL, $data);
}
foreach ($received as $r_k => $r_v) {
$data[$r_k] = is_array($r_v) ? IterableMarkup::create($r_v, NULL, $data) : IterableMarkup::create([], $r_v, $data);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment