# 2015-05-04 mes notes à http://jenny.bourdiol.org/content/technique-rwd-des-images-drupal-7-field-formatter-class /* * Implémente hook_theme_registry_alter */ function responsiveimages_theme_registry_alter(&$theme_registry) { if (isset($theme_registry['image'])) { $theme_registry['image']['function'] = 'responsiveimages_image'; } return $theme_registry; } /** * Surcharge theme_image */ function responsiveimages_image($variables) { //srcset $source = file_create_url($variables['path']); $srcset = get_srcset_for_image($source); if ($srcset) $variables['attributes']['srcset'] = $srcset; //sizes if (array_key_exists('class', $variables['attributes'])) { $classes = explode(" ", $variables['attributes']['class']); $sizes = get_sizes_for_image($classes); if (strlen($sizes)) $variables['attributes']['sizes'] = $sizes; } $attributes = $variables['attributes']; foreach (array('width', 'height', 'alt', 'title') as $key) { if (isset($variables[$key])) { $attributes[$key] = $variables[$key]; } } return ''; }