Drupal 7 – Programatically update a media module file display image style

I needed to push a change to a file display’s image style through to production, and Features didn’t seem to want to take it so I needed to push it via an update hook.

Using code from file_entity_file_display_form_submit() and media_install() i came up with this, which worked:

$display_name = 'video__preview__media_youtube_image';
$image_style = 'media_thumbnail';
$display = array(
  'api_version' => 1,
  'name' => $display_name,
  'status' => 1,
  'weight' => 2,
  'settings' => array('image_style' => $image_style),
  'export_type' => 3,
  'export_module' => 'media_youtube',
  'type' => 'Overridden',
  'table' => 'file_display',
);

file_display_save((object) $display);

Might be useful for someone in the future..

Published by

Sam

Drupal developer from Perth, Western Australia. I love programming, gaming, the Internet, growing vegetables and hiking.

Leave a Reply

Your email address will not be published. Required fields are marked *