Skip to content

Instantly share code, notes, and snippets.

@csakiistvan
Created August 16, 2016 08:28
Show Gist options
  • Save csakiistvan/39e35a2a5031da2bad462c1c1bd6c878 to your computer and use it in GitHub Desktop.
Save csakiistvan/39e35a2a5031da2bad462c1c1bd6c878 to your computer and use it in GitHub Desktop.
Drupal node image field links to other link field
<?php
/**
* @file
* Preprocessing functions for event nodes.
*/
/**
* Implements hook_preprocess_node().
*/
function _[yourthemename]_preprocess_field_name__[nodetypename]__[imagefieldname](&$variables) {
if (empty($variables['element']['#object']->linkfieldname['und'][0]['url'])) {
return;
}
foreach ($variables['items'] as &$item) {
$image = drupal_render($item);
$item = array(
'#type'=>'markup',
'#markup'=>l($image, $variables['element']['#object']->linkfieldname['und'][0]['url'], array(
'attributes' => array(
'target' => '_blank',
),
'html' => TRUE,
)
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment