Skip to content
Bryan Hazelbaker edited this page Jun 10, 2013 · 2 revisions

Inline conversion of existing files

Existing managed files can be converted while editing the containing node.

Drupal convert file inline conversion form

Automatic conversion of uploaded files

Manage fields page of a content type. Showing a new file field using the Convert File widget:

Manage fields configuration

Convert File widget exposes two new configuration elements to the field settings:

Convert File widget field settings

Field formatters

Display the current converted file, as well as all backups of previous versions.

Configuration:

Field formatter configuration

Display (this file was uploaded as .txt, auto converted to .odt, then later via inline conversion form to .pdf):

Field formatter display

File conversion is based on rules

While editing the reaction rule "CF Google Drive convert to PDF"

File conversion is based on rules

Programmatic file conversion

Code may also provide file conversion by calling the following function convertfile_convert_file(), though rules still provide the ultimate functionality.

/**
 * Programmatic wrapper for convertfile_validate_conversion().
 *
 * Call this function directly to perform a programmatically based conversion.
 * Rules, and even most programmatic functions, expect file conversion to be
 * initiated by an upload to a file field that has an instance configuration,
 * therefore this configuration must be mocked up if it does not really exist.
 *
 * @param int|stdClass $file
 *   The FID or file object to convert. This object may be modified.
 * @param string $provider
 *   The machine name of the provider.
 * @param string $format
 *   The machine name of the format to convert to.
 * @param array $specific
 *   The exact construction of options is dependent on the provider.
 *
 * @return bool
 *   TRUE on successful conversion, FALSE otherwise. See watchdog for error
 *   details.
 */
function convertfile_convert_file($file, $provider, $format, $extensions = NULL, $specific = NULL)

File conversion done inside validators

Any failed conversion happening during an upload will fail the entire upload via validation form errors.