Hi,
I spent about 7 hours today trying to use preprocessing functions with display suite enabled and a ds template applied on a content type. All tried hook functions from the ds api (like hook_ds_pre_render_alter) were completely ignored / not fired, and I couldn't figure out why.
Eventually, the problem appeared to be that I had (by chance) chosen a template, namely "2-column bricks", that wasn't a "native ds template", but a template belonging to the layout discovery module, but nevertheless selectable within the ds interface.
I had never expected these non-ds templates would be included without also making the ds api functions available to them.
I admit having had the apparently misplaced assumption that all ds functionality would be available to all templates it offers within its interface.
If the hook functions can't be made available to these templates, my question/suggestion would be to at least make it clear in the interface of managing displays.
If I am wrong about this conclusion, I would love to be corrected.
Thanks.
Comments
Comment #2
FNGR commentedSame here. hook_ds_pre_render_alter is just ignored :(
Comment #3
tezalsec commentedTry the preprocessing function of the layout discovery module, in your .theme file.
/*
* Hook for template_preprocess_layout, from module layout_discovery
* Applied through using 2-column brick layout within Display Suite interface on content type
*/
function mytheme_preprocess_layout(&$variables) {
...
}
Comment #4
FNGR commentedThank you! Will give it a try!
Comment #5
grimreaperHello,
On Drupal 8.6.0-beta2, I have the same problem.
Not passing in hook_preprocess_layout after overriding the template onecol from layout_discovery in my custom theme with a template suggestion.
hook_preprocess_layout and hook_ds_pre_render_alter ignored in custom module and custom theme.
Comment #6
sacarney commentedMaxim75's answer #3 https://www.drupal.org/project/ds/issues/2896561#comment-12185543 worked for me!
I was able to create a variable via theme settings, and make the variable available in my custom layout templates. Thank you!
Comment #7
swentel commentedComment #8
swentel commentedI've killed hook_ds_prerender_alter in #2912149: Change layout templates to use content.region (with BC) as it's indeed confusing when you're not selecting a layout that is 'managed' by DS.
From now on either use hook_preprocess_layout (that changed as well for good in 5.0.x) or hook_entity_view_alter to alter things.
There's either $variables['content']['#ds_variables'] or $build['#ds_variables'] available if DS is doing its thing.
DS (layouts) now also uses the same pattern as layout discovery does, meaning content.{region}, which means that any layout out there will work :)