Hi there.

Is there a way to allow the media/image field to have a per node formatter?

What I am aiming for is a radio box next to the widget on the edit/add screen which chooses which formatter (really, image size) is used upon display?

(my other option is to have multiple image/media fields and the user will choose which to use depending on what their desired image size is.)

Comments

naheemsays’s picture

Title: per node formatter? » per field formatter style?

Change in title to make it more accurate.

naheemsays’s picture

I have used the following code to allow me to change the image style on a per entity basis (I have only tested per node):

/**
 * Implements hook_field_display_alter() in order to allow nodes (entities?) to choose their image style on a per node basis.
 */

function therevival_field_display_alter(&$display, $context) {
  // If the field is an image, then change the display settings depending on the value of the image size choice.
  if ($display['type'] == 'image' && !empty($context['entity']->field_image_style)) {
    //get the preferred display size from the relevant field.
    $language = $context['entity']->language;
    $image_style = $context['entity']->field_image_style[$language][0]['value'];
    
    //Change the view mode
    if ($image_style <> '') {
      $display['settings']['image_style'] = $image_style;
    }
  }
}

Use this in conjunction with a text field called image_style which sets the name of the image style that you want the main image to be displayed with.

johnv’s picture

Upon searching for this functionality, I found these modules. I haven't tested them yet:
http://drupal.org/sandbox/dman/1434822
http://drupal.org/project/formatter_field

mrfelton’s picture

The formatter_field module works pretty well.

mpgeek’s picture

Status: Active » Closed (works as designed)

No need to duplicate function. The formatter_field project takes care of this issue.

siefca’s picture

Title: per field formatter style? » Per field formatter style?
Status: Closed (works as designed) » Active

Formatter Field is not utilizing file entity, it's just another formatter. You can choose to use it instead of rendered file entity, but then you will loose any additional fields you added to image file entity.

Actually it is possible to use file entity with desired display mode. :)

siefca’s picture

Status: Active » Closed (works as designed)