Skip to main content

Posts

Showing posts from August, 2018

Change picture mapping conditionally according to field value drupal 7

Hi Drupalars, Recently i got a task  "to provide an option in paragraph item to display a image grid 3 by 3 or 2 by 2" 3 by 3 grid 2 by 2 grid Adding conditional classes was fairly easy for each case , which is achieved by following code /** * Implements hook_preprocess_entity(). */ function YOURTHEME_preprocess_entity(&$variables) { if (!empty($variables['elements']['#entity']->field_show_50_50)) { if ($variables['elements']['#entity']->field_show_50_50['und'][0]['value'] == "1") { $variables['classes_array'][] = 'show-50-50'; }; } if (!empty($variables['elements']['#entity']->field_show_100)) { if ($variables['elements']['#entity']->field_show_100['und'][0]['value'] == "1") { $variables['classes_array'][] = 'show-100'; };