Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function YOURTHEME_preprocess_node(&$variables)
- {
- if (!isset($variables['field_image']) || !isset($variables['field_alignment'])) {
- return false; // if 1 of both fields is not available, don't do anything
- }
- $alignment = reset($variables['field_alignment']); // retrieve first item of array
- $variables['content']['field_image']['#extra_classes'] = array($alignment['value']); // add an extra datamember containing an array with the value of the other field
- }
- function YOURTHEME_preprocess_field(&$variables)
- {
- $field = $variables['element'];
- if ($field['#field_name'] !== 'field_image') {
- return false; // only manipulate the image field
- }
- if (!isset($field['#extra_classes'])) {
- return false; // don't do anything if the array with extra classes is not available
- }
- $variables['classes_array'] = array_merge(
- $variables['classes_array'], $field['#extra_classes']); // merge the default field classes with the new added class
- }
- function YOURTHEME_preprocess_node(&$variables)
- {
- if (!isset($variables['field_collection']) || !isset($variables['field_classes'])) {
- return false;
- }
- if (!isset($variables['content']['field_collection'])) {
- return false;
- }
- $alignment = reset($variables['field_classes']);
- foreach (element_children($variables['content']['field_collection']) as $index) {
- foreach ($variables['content']['field_collection'][$index]['entity']['field_collection_item'] as &$field_collection_item) {
- if (!isset($field_collection_item['field_image'])) {
- continue;
- }
- $field_collection_item['field_image']['#extra_classes'] = array($alignment['value']);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement