Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. function YOURTHEME_preprocess_node(&$variables)
  2. {
  3. if (!isset($variables['field_image']) || !isset($variables['field_alignment'])) {
  4. return false; // if 1 of both fields is not available, don't do anything
  5. }
  6.  
  7. $alignment = reset($variables['field_alignment']); // retrieve first item of array
  8. $variables['content']['field_image']['#extra_classes'] = array($alignment['value']); // add an extra datamember containing an array with the value of the other field
  9. }
  10.  
  11. function YOURTHEME_preprocess_field(&$variables)
  12. {
  13. $field = $variables['element'];
  14. if ($field['#field_name'] !== 'field_image') {
  15. return false; // only manipulate the image field
  16. }
  17.  
  18. if (!isset($field['#extra_classes'])) {
  19. return false; // don't do anything if the array with extra classes is not available
  20. }
  21.  
  22. $variables['classes_array'] = array_merge(
  23. $variables['classes_array'], $field['#extra_classes']); // merge the default field classes with the new added class
  24. }
  25.  
  26. function YOURTHEME_preprocess_node(&$variables)
  27. {
  28. if (!isset($variables['field_collection']) || !isset($variables['field_classes'])) {
  29. return false;
  30. }
  31.  
  32. if (!isset($variables['content']['field_collection'])) {
  33. return false;
  34. }
  35.  
  36. $alignment = reset($variables['field_classes']);
  37. foreach (element_children($variables['content']['field_collection']) as $index) {
  38. foreach ($variables['content']['field_collection'][$index]['entity']['field_collection_item'] as &$field_collection_item) {
  39. if (!isset($field_collection_item['field_image'])) {
  40. continue;
  41. }
  42.  
  43. $field_collection_item['field_image']['#extra_classes'] = array($alignment['value']);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement