Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I created a template for the group overview page but could not hook into preprocess in my custom module. So, I added it to the group module. This allows other modules to create hook_preprocess_group_bundle_view functions so that variables can be sent to custom templates.
Comment | File | Size | Author |
---|---|---|---|
templatepreprocess.patch | 862 bytes | bletch | |
Comments
Comment #2
kristiaanvandeneyndeI think Entity API provides those preprocess functions for us, no?
Like hook_preprocess_entity() and I think even hook_preprocess_group?
Comment #3
bletch CreditAttribution: bletch as a volunteer commentedI could not get hook_preprocess_entity to fire in my custom module. I had to add the hook into the group module to trigger the hook_preprocess_group in my custom module. Maybe something else was going on with my setup but it was the only way I could get those preprocess hooks to fire.
Comment #4
kristiaanvandeneyndeRight, what you need is
hook_preprocess_entity()
. Then check if$variables['entity_type'] == 'group'
Comment #6
isaachorton CreditAttribution: isaachorton commentedis any way someone can post a code example of how this would be implemented, Im a designer trying to style a theme for the group module and I cant figure out how to get $group variables into the templates? Cant seem to find a code example anywhere. ive searched hi and lo. Specifically, i want to render an image field from the group in the page--group.tpl.php but outside of the content, just above the title. I can access the variable in the devel module and target the field that way, but then the id of the group is passed and so will only load 1 groups image, but the goal is to load a header image for each group that is unique to the group and comes from a field of the group, ie an image field.
I know it's probably really easy for someone, but for me this is nearly impossible to figure out. Any help would be greatly appreciated!
Comment #7
kristiaanvandeneyndeLook at
template_preprocess_entity()
It should work out of the box
Comment #8
isaachorton CreditAttribution: isaachorton commentedThanks for the example Kristiaan!
I added the code you provided above to my custom module and it seems to be creating the template suggestions but my snippet of code I usually use for inserting fields(on page.tpl.php templates) from nodes is not working. How can I alter this code to target the group entity type since the node variable is not available? my field is "field_header_image". thanks again.
Comment #9
kristiaanvandeneyndeYou shouldn't copy any of the code above (#7), Entity API runs that for you for any custom entity type (group, commerce product, ...).
What I was saying is that you should have a $group variable in group.tpl.php out of the box, just as you should have a $node variable in node.tpl.php out of the box because the node module takes care of that in template_preprocess_node().
Maybe you're getting confused by the theming layer a little bit :) This link has some documentation on preprocessors: https://www.drupal.org/node/223430
P.S.: Even though you shouldn't call field_view_field() in a template, it would look like this:
Comment #10
isaachorton CreditAttribution: isaachorton commentedcool thanks