Skip to content

Commit

Permalink
Add hashes to preview render arrays recursively nuvoleweb#39
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksip committed Jan 26, 2017
1 parent 6f0bec6 commit 41218a6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Element/PatternPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ public static function processFields(array $element) {
*/
protected static function getPreviewMarkup($preview) {
if (is_array($preview)) {
// Check if preview is a render array.
if (array_key_exists('theme', $preview) || array_key_exists('type', $preview)) {
$rendered = [];
foreach ($preview as $key => $value) {
$rendered['#' . $key] = $value;
$rendered = [];
$hashKeys = array_key_exists('theme', $preview) || array_key_exists('type', $preview);
foreach ($preview as $key => $value) {
if ($hashKeys) {
$key = '#' . $key;
}

return $rendered;
if (is_array($value)) {
$value = self::getPreviewMarkup($value);
}
$rendered[$key] = $value;
}

// Recursively escape the string elements.
return array_map([self::class, __METHOD__], $preview);
return $rendered;
}

return Markup::create($preview);
Expand Down

0 comments on commit 41218a6

Please sign in to comment.