public function StaticLayout::renderLayout in Layout 8.2
Implements Drupal\layout\Plugin\LayoutInterface::renderLayout().
Overrides LayoutInterface::renderLayout
File
- lib/
Drupal/ layout/ Plugin/ Layout/ StaticLayout.php, line 78 - Contains \Drupal\layout\Plugin\Layout\StaticLayout.
Class
- StaticLayout
- Plugin annotation @Plugin( id = "static_layout", derivative = "Drupal\layout\Plugin\Derivative\Layout" )
Namespace
Drupal\layout\Plugin\LayoutCode
public function renderLayout($admin = FALSE, $regions = array()) {
$definition = $this
->getPluginDefinition();
// Assemble a render array with the regions and attached CSS/JS.
$build = array(
'#theme' => $definition['theme'],
'#content' => array(),
'#attributes' => array(
'class' => drupal_html_class($definition['theme']),
),
);
// Render all regions needed for this layout.
foreach ($this
->getRegions() as $region => $info) {
// Initialize regions which were not provided as empty.
$build['#content'][$region] = empty($regions[$region]) ? '' : $regions[$region];
}
// Fill in attached CSS and JS files based on metadata.
if (!$admin) {
$build['#attached'] = array(
'css' => $this
->getStylesheetFiles(),
'js' => $this
->getScriptFiles(),
);
}
else {
$build['#attached'] = array(
'css' => $this
->getAdminStylesheetFiles(),
'js' => $this
->getAdminScriptFiles(),
);
}
// Include the path of the definition in all CSS and JS files.
foreach (array(
'css',
'js',
) as $type) {
foreach ($build['#attached'][$type] as &$filename) {
$filename = $definition['path'] . '/' . $filename;
}
}
return drupal_render($build);
}