3

I want to display images at the proper image style-defined size, but there's a problem being caused by a preprocess function written by the person who built this site before I came onto the project.

function abc_field__field_video_thumbnail($variables) {
    $output = '';

    // Render the items
    foreach ($variables['items'] as $item) {
        $output .= "<div class=\"field-item\">\r";
        $output .= '<a href="' . $movieurl . '" target="popup" data-popup-width="' . $variables['element']['#object']->field_video_width['und'][0]['value'] . '" data-popup-height="' . $variables['element']['#object']->field_video_height['und'][0]['value'] . '">';
        $output .= '<img src="' . file_create_url($item['#item']['uri']) . '" alt="" width="' . $item['#item']['width'] . '" height="' . $item['#item']['height'] . '" class="' . $item['#image_style'] . '">' . "\r";
        $output .= '<img src="/' . drupal_get_path('theme', 'nwe').'/images/button_play.png' . '" alt="Play Video" width="110" height="110" class="play-icon">' . "\r";
        $output .= "</a>\r\r";
        $output .= "</div>\r\r";
}

    // Render the top-level div
    $output = '<div class="' . $variables['classes'] . '"' . $variables['attributes'] . '>' . $output . '</div>';

    return $output;
}

This seems to assume the image style processing would occur before this function happened, but unfortunately it doesn't, and I get a full-size image regardless of image style.

1 Answer 1

2

By taking over the display of that field you're actually bypassing all the field system would usually do to apply the custom display settings; it basically passes off the responsibility of creating the field HTML to you, and provides you with the raw values you'll need to build it up.

So if you want to output a style based image, you'll need to do it manually using theme_image_style():

$args = array('style_name' => 'thumbnail', 'path' => $item['#item']['uri'], 'alt' => 'Alt text');
$image = theme('image_style', $args);

// Append $image to your output...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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