function pdfthumb_process in PDFThumb 7
Find a PDF field for generate a thumb after saving or updating a node
Parameters
object $entity: The entity that is being inserted or updated.
string $type: The entity name.
1 call to pdfthumb_process()
- pdfthumb_entity_presave in ./
pdfthumb.module - Implements hook_entity_presave().
File
- ./
pdfthumb.module, line 166 - Give a way to create pdf thumbnails.
Code
function pdfthumb_process($entity, $type) {
global $user;
// When we save bundles check for a configured file field.
if (is_object($entity)) {
// Get the current bundle name Ex: User / News / Page
$current_bundle = pdfthumb_entity_get_bundle($entity, $type);
foreach (field_info_instances($type, $current_bundle) as $key => $value) {
// If this file has been configured.
if (variable_get("pdfthumb_" . $current_bundle . "_" . $key, NULL)) {
$img_dest = variable_get("pdfthumb_" . $current_bundle . "_" . $key);
$pdf_field = field_get_items($type, $entity, $key);
// If the pdf file exist
if (isset($pdf_field[0]['fid'])) {
// Check convert path is configured
if (variable_get('pdfthumb_convertpath', NULL)) {
// If the option media library is selected for this file.
if ($img_dest == "media") {
pdfthumb_create_thumb($pdf_field[0]['fid']);
}
elseif ($img_dest != "none") {
// Create a thumb file and link it with the specified field.
$field_lg = field_language($type, $entity, $img_dest);
$file = pdfthumb_create_thumb($pdf_field[0]['fid']);
// If the file has been created
if ($file) {
$entity->{$img_dest} = array(
$field_lg => array(
0 => array(
'fid' => $file->fid,
'filename' => $file->filename,
'filemime' => $file->filemime,
'uid' => $user->uid,
'uri' => $file->uri,
'status' => 1,
),
),
);
}
}
}
else {
watchdog("pdfthumb", "Convert path not found. No PDF thumbnails generate", array(), WATCHDOG_WARNING);
}
}
}
}
}
}