Python俱乐部
Python
小课题
京东优惠券
修改了 imagefield 中到原始图片的链接,实现到指定链接的功能。
修改文件 imagefield/imagefield_formatter.inc
function theme_imagefield_formatter_image_imagelink($element) { // Inside a view $element may contain null data. In that case, just return. if (empty($element['#item']['fid'])) { return ''; } $item = $element['#item']; $original_image_url = file_create_url($item['filepath']); $class = 'imagefield imagefield-imagelink imagefield-'. $element['#field_name']; # return l($imagetag, $original_image_url, array('attributes' => array('class' => $class), 'html' => TRUE)); $imagetag = theme('imagefield_formatter_image_plain', $element); # drupal_set_message( "<pre>" . print_r($imagetag, true) . "</pre>"); $node = $element['#node']; return l($imagetag, $node->field_url[0]["value"], array('attributes' => a rray('class' => $class), 'html' => TRUE)); }
主要加了下面两行:
$node = $element['#node']; return l($imagetag, $node->field_url[0]["value"], array('attributes' => a rray('class' => $class), 'html' => TRUE));
修改文件 imagecache/imagecache.module
function theme_imagecache_formatter_imagelink($element) { // Inside a view $element may contain NULL data. In that case, just return. if (empty($element['#item']['fid'])) { return ''; } // Extract the preset name from the formatter name. $presetname = substr($element['#formatter'], 0, strrpos($element['#formatter'], '_')); $style = 'imagelink'; $item = $element['#item']; $item['data']['alt'] = isset($item['data']['alt']) ? $item['data']['alt'] : ''; $item['data']['title'] = isset($item['data']['title']) ? $item['data']['title'] : NULL; $imagetag = theme('imagecache', $presetname, $item['filepath'], $item['data']['alt'], $item['data']['title']); $path = file_create_url($item['filepath']); $class = "imagecache imagecache-$presetname imagecache-$style imagecache-{$element['#formatter']}"; $node = $element['#node']; #drupal_set_message ( "<pre>" . $class ."</pre>" ); return l($imagetag, $node->field_url[0]["value"], array('attributes' =>array('class' => $class, "target" => "_blank"), 'html' => TRUE)); #return l($imagetag, $path, array('attributes' => array('class' => $class), 'html' => TRUE)); }