function template_preprocess_ds_entity_view in Display Suite 8.2
Same name and namespace in other branches
- 8.4 ds.module \template_preprocess_ds_entity_view()
- 8.3 ds.module \template_preprocess_ds_entity_view()
Process entity view.
File
- ./
ds.module, line 274 - Display Suite core functions.
Code
function template_preprocess_ds_entity_view(&$variables) {
$build = $variables['content'];
$configuration = $build['#ds_configuration'];
// Process the render array so we can reuse it.
// Don't add/override the cache key if there aren't any.
if (!empty($build['#cache']['keys'])) {
$build['#cache']['keys'][0] = 'ds_entity_view';
}
unset($build['#theme']);
unset($build['#pre_render']);
unset($build['#sorted']);
unset($build['#children']);
unset($build['#render_children']);
unset($build['#prefix']);
unset($build['#suffix']);
unset($build['#attached']['html_head_link']);
// Create region variables based on the layout settings.
$use_field_names = \Drupal::config('ds.settings')
->get('use_field_names');
$regions = [];
foreach (array_keys($configuration['regions']) as $region_name) {
$regions[$region_name] = array();
// Create the region content.
if (!empty($configuration['regions'][$region_name])) {
foreach ($configuration['regions'][$region_name] as $key => $field) {
// Make sure the field exists.
if (!isset($build[$field])) {
continue;
}
if (!isset($build[$field]['#weight'])) {
$build[$field]['#weight'] = $key;
}
if ($use_field_names) {
$regions[$region_name][$field] = $build[$field];
}
else {
$regions[$region_name][$key] = $build[$field];
}
}
}
}
$layout = Layout::layoutPluginManager()
->createInstance($configuration['layout']['id'], $configuration['layout']['settings']);
$build = array_merge($build, $layout
->build($regions));
// Disable CSS files when needed.
if ($build['#ds_configuration']['layout']['disable_css']) {
$library = $build['#ds_configuration']['layout']['library'];
$attached = $build['#attached']['library'];
$index = array_search($library, $attached);
unset($build['#attached']['library'][$index]);
}
$variables['content'] = $build;
}