function file_type_save

×

Error message

User warning: The following module is missing from the file system: theme/theme. For information about how to fix this, see the documentation page. in _drupal_trigger_error_with_delayed_logging() (line 1156 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
cis7 file_entity.file_api.inc file_type_save($type)
cle7 file_entity.file_api.inc file_type_save($type)
elmsmedia7 file_entity.file_api.inc file_type_save($type)
icor7 file_entity.file_api.inc file_type_save($type)
meedjum_blog7 file_entity.file_api.inc file_type_save($type)
mooc7 file_entity.file_api.inc file_type_save($type)

Updates an existing file type or creates a new one.

This function can be called on its own, or via the CTools exportables 'save callback' for {file_type} objects.

Related topics

5 calls to file_type_save()
file_entity_file_type_form_submit in sites/all/modules/ulmus/file_entity/file_entity.admin.inc
Form submission handler for file_entity_file_type_form().
file_entity_update_7210 in sites/all/modules/ulmus/file_entity/file_entity.install
Merge MIME types into the {file_type} table.
media_update_7208 in sites/all/modules/ulmus/media/media.install
Drop the media_types table and migrate files to file_entity types.
media_update_7212 in sites/all/modules/ulmus/media/media.install
Re-create application file type for legacy reasons.
media_upgrade_file_types_confirm_submit in sites/all/modules/ulmus/media/includes/media.pages.inc
File types migration confirmation page sumit. Executes actual migration.
2 string references to 'file_type_save'
file_entity_schema in sites/all/modules/ulmus/file_entity/file_entity.install
Implements hook_schema().
file_entity_update_7201 in sites/all/modules/ulmus/file_entity/file_entity.install
Add the {file_type}, {file_type_mimetypes} tables.

File

sites/all/modules/ulmus/file_entity/file_entity.file_api.inc, line 493
API extensions of Drupal core's file.inc.

Code

function file_type_save($type) {
  // Get the old type object, so we now can issue the correct insert/update
  // queries.
  if (!empty($type->old_type) && $type->old_type != $type->type) {
    $rename_bundle = TRUE;
    $old_type = file_type_load($type->old_type);
  }
  else {
    $rename_bundle = FALSE;
    $old_type = file_type_load($type->type);
  }

  // The type and label fields are required, but description is optional.
  if (!isset($type->description)) {
    $type->description = '';
  }
  $fields = array(
    'type' => $type->type,
    'label' => $type->label,
    'description' => $type->description,
    'mimetypes' => serialize($type->mimetypes),
  );

  // Update an existing type object, whether with a modified 'type' property or
  // not.
  if ($old_type) {
    if ($old_type->export_type & EXPORT_IN_DATABASE) {
      db_update('file_type')->fields($fields)->condition('type', $old_type->type)->execute();
    }
    else {
      db_insert('file_type')->fields($fields)->execute();
    }
    if ($rename_bundle) {
      field_attach_rename_bundle('file', $old_type->type, $type->type);
    }
    module_invoke_all('file_type_update', $type);
    $status = SAVED_UPDATED;
  }
  // Insert a new type object.
  else {
    db_insert('file_type')->fields($fields)->execute();
    field_attach_create_bundle('file', $type->type);
    module_invoke_all('file_type_insert', $type);
    $status = SAVED_NEW;
  }

  // Clear the necessary caches.
  file_info_cache_clear();

  // Ensure the type has the correct export_type in case the $type parameter
  // continues to be used by the calling function after this function completes.
  if (empty($type->export_type)) {
    $type->export_type = 0;
  }
  $type->export_type |= EXPORT_IN_DATABASE;

  return $status;
}