Function utile pour Drupal 6
Submitted by yvan on Tue, 06/21/2011 - 17:37
Voilà déjà pas mal de temps que je travaille avec Drupal et à force on commence à se construire des outils qu'on utilise un peu partout sur tous les sites. Ici vous allez trouvez une des fonctions que j'utilise le plus, le
getImg.
Cette fonction à placer dans le fichier template.php de votre theme permet de récupérer très facilement une image associée à un node grâce au module imafieldfield et de renvoyer toutes les informations nécessaires
<?php function getImg($node, $preset = NULL, $attributes = NULL, $index = 0, $field = 'field_images') { if (!is_object($node) || !is_array($node->{$field})) { return FALSE; } $image = $node->{$field}[0]; if (is_int($index) && $index > 0) { $image = $node->{$field}[$index]; } if (!file_exists($image['filepath'])) { return FALSE; } $alt = $image['data']['alt']; $title = $image['data']['title']; $description = $image['data']['description']; $attributes = is_array($attributes) ? array_merge($attributes, $attributes) : array(); if (!empty($preset)) { $src = theme('imagecache', $preset, $image['filepath'], $alt, $title, $attributes); $url = imagecache_create_url($preset, $image['filepath']); } else { $src = theme('image', $image['filepath'], $alt, $title, $attributes); url($GLOBALS['base_url'] . $image['filepath'], array('absolute' => TRUE)); } return array( 'alt' => $alt, 'title' => $title, 'description' => $description, 'src' => $src, 'url' => $url, ); } ?>





Recent comments
40 weeks 1 day ago
46 weeks 4 days ago
46 weeks 6 days ago
50 weeks 5 days ago
50 weeks 5 days ago
50 weeks 6 days ago
1 year 3 weeks ago
1 year 5 weeks ago
1 year 5 weeks ago
1 year 5 weeks ago