-
Notifications
You must be signed in to change notification settings - Fork 3
Developer Hooks
- hook_convertfile_info()
- hook_convertfile_pre_convert()
- hook_convertfile_post_convert()
Declare a new provider and conversion formats. Provider and associated formats will be available as options when configuring file field instances, on the inline conversion form, and on the admin convert tab. Unless a callback is specified, new rules must be created to perform the actual conversion.
Example implementation uses a callback for documentation only. The actual imagemagick hook_convertfile_info() makes use of rules and therefore does not specify a callback function.
Example implementation:
/**
* Implements hook_convertfile_info().
*
* Register our provider and formats with convertfile module.
*
* @see convertfile_collect_info()
*/
function cf_imagemagick_convertfile_info() {
return array(
// Preface array structure with module machine name.
'cf_imagemagick' => array(
// Human friendly name of provider.
'name' => 'ImageMagick',
// Extensions that this provider will convert to.
'types' => array(
'png' => '.png (image/png)',
'jpg' => '.jpg (image/jpeg)',
),
// Provider specific options callback (optional).
'options' => 'cf_imagemagick_options',
// Provider specific options submission formatter callback (optional).
'exposed_options' => 'cf_imagemagick_options_exposed',
// Friendly link for help with this provider (optional).
'help' => array(
'url' => 'https://github.com/delphian/drupal-convert-file/wiki/ImageMagick',
),
),
);
}Perform operations on the file before it is converted. As $file is an object it will retain any changes made to it.
Example implementation:
/**
* Implements hook_convertfile_pre_convert().
*
* For some strange undisclosed reason abort any conversion to pdf documents
* before it happens.
*
* @param stdObject $file
* The file object on which to operate. We will be altering this value. Pass
* by reference operator is not required for objects.
* @param array $instance
* The file field configuration instance associated with this file.
*
* @return void
* We return nothing.
*/
function convertfile_convertfile_pre_convert($file, $instance) {
// Only for newly uploaded files
if (!isset($file->fid)) {
$to_format = $instance['widget']['settings']['convertfile_ajax']['convertfile_format'];
if ($to_format == 'pdf') {
// Set an error message. The existance of an error message will bypass
// any conversion. Error messages will also trip form validation.
$file->convertfile['error'] = "Conversion to PDF not allowed!".
}
}
}@param stdObject $file
@param array $instance
@return void
Perform operations on the file after it is converted. As $file is an object it will retain any changes made to it.