In some programatic changes that I was adding to a module of our own were unable to load the display so that the ->status attribute could be set.

I traced this down to a condition where any database that hasn't had the admin form for the file display configuration set up would not be able to call that function and yield a valid response.

Once the form is submitted the file_displays_load and file_display_save calls both work.

Comments

tahiche’s picture

Issue summary: View changes

Hi,
If I understand correctly, I faced a similar issue where I had defined "hook_file_default_displays()" in my custom module to create a file type and have the right displays. My "file_default_displays()" function I got after exporting a feature and copying the result, with all the formats and settings for my file type.
Like you point out, and I don´t know if it´s the same scenario, these default displays are not recorded to database but read from that file until you save the display form (for each view mode).
Based on the issue Default file entities are not exportable by features regarding the default types not being saved to DDBB and thus not exportable, I´m saving these defaults on module enabling (you can do it on install too, i guess).

Something like this...


/**

 * Implements hook_file_default_types().
 * Create our custom file type
 */
function my_module_file_default_types() {
  $types = [];
  // Video.
  $types['my_custom_file_type'] = (object) [
    'api_version' => 1,
    'type' => 'my_custom_file_type',
    'label' => t('It´s a custom file type'),
    'description' => t('<em>Video recording</em>. moving thing'),
    'mimetypes' => [
      'video/*',
    ],
  ];
  return $types;
}


/**
 * Implements hook_enable().
**/
function my_module_enable() {

  // do stuff here

  /**
   * Record the default_displays to DDBB so we can export with features.
   * Otherwise only triggered on display form "save"
   */
  $view_modes=['default','teaser','preview','entityreference_view_widget'];
  foreach($view_modes as $view_mode){
    $existing_display = file_displays_load('my_custom_file_type', $view_mode);
    foreach ($existing_display as $displayObj){
      $res=file_display_save((object) $displayObj);
    }
  }
}