Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I've to create a custom function to display images because I've to add values from custom fields.

I've added a function to template php, like this:

function mytheme_image($variables) {  
}

The problem is that in $variables I haven't the fid of the file, but only the path. I have to load the file to get values from field, how should I do?

I'm looking for functions to get fid from path but I haven't found something..

share|improve this question

2 Answers 2

Assuming you want to change the image field output - you might want to look at the theme_image_formatter function that you can override and add your variables to the $image var, that will be later sent to theme_image or theme_image_style.

Be aware, that theme_image is working with the paths, so it is possible that the function is not called from within the theme_image_formatter.

share|improve this answer
    
I've tried it, but using netbeans the system doesn't enter in the function while shows images. –  arrubiu Nov 12 '12 at 13:16
    
so are the images coming through the image field and displayed as such? –  Marek Sotak Nov 12 '12 at 13:45
    
Images are "file" field, with "media selector" as widget, and displayed as "rendered entity" –  arrubiu Nov 12 '12 at 13:50

Suggestions about formatting are helpful, but to answer the actual question, the answer at https://drupal.org/comment/6493610#comment-6493610 looks good.

// Take a look at: file.inc::file_load_multiple
$files = file_load_multiple(array(), array('uri' => $uri));
$file = reset($files); 
// If empty, $file will be false, otherwise will contain the required file

A two-liner instead of one, but should get the result we need.

share|improve this answer
    
$conditions is marked deprecated in file_load_multiple() so what to do instead? –  pvorb Oct 8 at 10:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.