protected function PatternsLibraryController::getPatternRenderArray in UI Patterns 8
Get pattern preview render array, handling variants.
Parameters
\Drupal\ui_patterns\Definition\PatternDefinition $definition: Pattern definition object.
Return value
array Render array.
2 calls to PatternsLibraryController::getPatternRenderArray()
- PatternsLibraryController::overview in modules/
ui_patterns_library/ src/ Controller/ PatternsLibraryController.php - Render pattern library page.
- PatternsLibraryController::single in modules/
ui_patterns_library/ src/ Controller/ PatternsLibraryController.php - Render pattern library page.
File
- modules/
ui_patterns_library/ src/ Controller/ PatternsLibraryController.php, line 108
Class
- PatternsLibraryController
- Class PatternLibraryController.
Namespace
Drupal\ui_patterns_library\ControllerCode
protected function getPatternRenderArray(PatternDefinition $definition) {
$render = [];
// If pattern has variants then render them all adding meta information
// on top of each one, or simply render pattern preview otherwise.
if ($definition
->hasVariants()) {
foreach ($definition
->getVariants() as $variant) {
$render[$definition
->id() . '_' . $variant
->getName()] = [
'meta' => [
'#theme' => 'patterns_variant_meta_information',
'#variant' => $variant
->toArray(),
],
'pattern' => [
'#type' => 'pattern_preview',
'#id' => $definition
->id(),
'#variant' => $variant
->getName(),
'#theme_wrappers' => [
'container' => [
'#attributes' => [
'class' => 'pattern-preview__markup pattern-preview__markup--variant_' . $variant
->getName(),
],
],
],
],
];
}
}
else {
$render[$definition
->id()] = [
'pattern' => [
'#type' => 'pattern_preview',
'#id' => $definition
->id(),
'#theme_wrappers' => [
'container' => [
'#attributes' => [
'class' => 'pattern-preview__markup',
],
],
],
],
];
}
return $render;
}