Created
August 16, 2016 08:28
-
-
Save csakiistvan/39e35a2a5031da2bad462c1c1bd6c878 to your computer and use it in GitHub Desktop.
Drupal node image field links to other link field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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