I'm trying to add a class to the region div based on a field value.
For example:
Inside my node I have a field where a user can select an option from some radio buttons. I would like to take the value of that field and add it to the classes used on <div class="ds-1col node node-page node-odd view-mode-full clearfix">
I've done this in the past for fields by using the ds_extras module that comes with ds which provides a theme function theme_ds_field_minimal.
It seems like the function that adds classes to the DS regions is ds_entity_variables. At the end it runs an alter drupal_alter('ds_pre_render', $layout_render_array, $context);
I've tried using hook_ds_pre_render_alter but the classes don't seem to be available.
I'm not sure if there is a way to do this now or if a feature / hook needs to be added for this to work. Any help would be greatly appreciated.
Comment | File | Size | Author |
---|---|---|---|
#2 | ds-1645500-2.patch | 1.48 KB | dawehner |
Comments
Comment #1
swentel CreditAttribution: swentel commentedYeah, the $vars aren't passed in, I'm still not sure whether I want to do that or not.
You can also just implement hook_preprocess_node, that's the easiest way to add the class now.
Comment #2
dawehnerWell hook_preprocess_node doesn't really work if you do something for all entities.
Here is a patch which adds a last parameter (so existing functions are not affected) and also an adaption for the docs.
Btw.
This code doesn't work together with omega 4, because it unsets references, see omega_initialize_attributes() and omega_cleanup_attributes(),
but I'm not sure how to proper implement it here. Maybe it would be possible to detect the reference by comparing the classes?
Comment #3
dawehnerAdapt status
Comment #4
dawehnerI know that this was needed for a custom project but yeah I have no idea how urgent that was.
Comment #5
aspilicious CreditAttribution: aspilicious commentedI thought about this for a while and I'm going to do this. It doesn't hurt...
Marking rtbc so I don't forget...
Comment #6
aspilicious CreditAttribution: aspilicious commentedFixed, needs porting to D8.
Comment #7
aspilicious CreditAttribution: aspilicious commentedDone
Comment #8
aspilicious CreditAttribution: aspilicious commentedComment #9
bendev CreditAttribution: bendev commentedHello,
I did not manage to do this. Could you please detail how you proceed?
Is this compatible with theme omega4?
I have the impression that the hook is not fired.
Thanks
Comment #10
kopeboy CreditAttribution: kopeboy commentedCan we have this on Drupal 7?
Comment #12
aspilicious CreditAttribution: aspilicious commentedI won't be adding more features to D7.