I have created an empty custom view mode for file entities with hook_entity_info_alter().

I would like to programmatically select settings for it, so that they can be deployed without a user having to go to the file entity display settings GUI and select "image" for type of file display and "original size" for the image style.

I cannot do this with hook_entity_view_mode_alter() because that appears to only fire for nodes, not for file entities.

How can I programmatically set the display settings for my custom view mode for file entities?

  • Just to clarify: are you actually using the File Entity module?
    – Clive
    Aug 20, 2014 at 17:01
  • Did you try the Display Suite module? It's perfectly deployed using Features
    – milkovsky
    Aug 20, 2014 at 23:32
  • DS+Features (neither of which is in use on this site currently) seems like a pretty heavy solution for the problem of how to set a couple of variables.
    – beth
    Aug 21, 2014 at 15:22

1 Answer 1


Sounds like something like this should work for you, to set the file display for the image file type, view mode name VIEW_MODE (replace with your custom view mode), to display original image. It either adds a new file display or updates an existing one:

$displays = file_displays_load('image', 'VIEW_MODE', TRUE);
$formatter = 'file_field_image';
if (array_key_exists($formatter, $displays)) {
  $display = $displays[$formatter];
else {
  $display = (object) array(
    'api_version' => 1,
    'name' => 'image__VIEW_MODE__' . $formatter,
$display->status = 1;
$display->settings['image_style'] = '';

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.