public static function PatternPreview::getPreviewMarkup in UI Patterns 8
Make previews markup safe.
Parameters
string|string[] $preview: The preview, may be a string or an array.
Return value
array|\Drupal\Component\Render\MarkupInterface|string Preview safe markup.
2 calls to PatternPreview::getPreviewMarkup()
- PatternPreview::processFields in src/
Element/ PatternPreview.php - Process fields.
- PatternPreviewTest::testPreviewMarkup in tests/
src/ Unit/ Element/ PatternPreviewTest.php - Test getPreviewMarkup.
File
- src/
Element/ PatternPreview.php, line 56
Class
- PatternPreview
- Renders a pattern preview element.
Namespace
Drupal\ui_patterns\ElementCode
public static function getPreviewMarkup($preview) {
if (is_array($preview)) {
$rendered = [];
// If preview is a render array add hashes to keys.
$hash_keys = array_key_exists('theme', $preview) || array_key_exists('type', $preview);
foreach ($preview as $key => $value) {
$key = $hash_keys ? '#' . $key : $key;
if (is_array($value)) {
// Process array values recursively.
$value = self::getPreviewMarkup($value);
}
$rendered[$key] = $value;
}
return $rendered;
}
return Markup::create($preview);
}