You are here

function _picture_update_to_file_entity_2 in Picture 7

Same name and namespace in other branches
  1. 7.2 picture.admin.inc \_picture_update_to_file_entity_2()

Update picture module to version 2 of File Entity module.

2 calls to _picture_update_to_file_entity_2()
picture_admin_settings_submit in ./picture.admin.inc
picture_update_7001 in ./picture.install
Update to the new file display formatter provided by file_entity.module.

File

./picture.admin.inc, line 249
Picture - map breakpoints and image styles

Code

function _picture_update_to_file_entity_2() {

  // File Entity is not installed or the installed version is not version 2.
  if (!module_exists('file_entity') || !function_exists('file_type_load_all')) {
    return FALSE;
  }

  // Picture was already updated.
  if (variable_get('picture_updated_to_file_entity_2', FALSE)) {
    return TRUE;
  }
  $entity_info = entity_get_info('file');
  $types = file_type_load_all();
  foreach ($types as $file_type) {
    $view_modes = array(
      'default' => array(
        'label' => t('Default'),
      ),
    ) + $entity_info['view modes'];
    foreach (array_keys($view_modes) as $view_mode) {
      $current_displays = file_displays_load($file_type->type, $view_mode, TRUE);
      if (isset($current_displays['file_picture']) && $current_displays['file_picture']->status) {
        if (!isset($current_displays['file_field_picture']) || !$current_displays['file_field_picture']->status) {
          $display = clone $current_displays['file_picture'];
          $display->name = isset($current_displays['file_field_picture']) ? $current_displays['file_field_picture']->name : $file_type->type . '__' . $view_mode . '__file_field_picture';
          unset($display->settings['alt']);
          unset($display->settings['title']);
          $display->settings['image_link'] = '';
          $display->settings['colorbox'] = $display->settings['picture_group'];
          $current_displays['file_field_picture'] = $display;
          unset($current_displays['file_picture']);
          file_display_save($display);
        }
      }
      elseif (isset($current_displays['file_field_picture'])) {
        $display = $current_displays['file_field_picture'];
        $display->settings['picture_mapping'] = isset($display->settings['picture_mapping']) ? $display->settings['picture_mapping'] : $display->settings['picture_group'];
        unset($display->settings['picture_group']);
        file_display_save($display);
      }
    }
  }
  return TRUE;
}