You are here

function fillpdf_save_to_file in FillPDF 7.2

Same name and namespace in other branches
  1. 7 fillpdf.deprecated.inc \fillpdf_save_to_file()
2 calls to fillpdf_save_to_file()
fillpdf_merge_handle_pdf in ./fillpdf.module
Figure out what to do with the PDF and do it.
fillpdf_rules_action_save_to_file in ./fillpdf.rules.inc
Save the PDF to a file and return the file path.

File

./fillpdf.module, line 663
Allows mappings of PDFs to site content

Code

function fillpdf_save_to_file($pdf_info, $pdf_data, $token_objects, $output_name, $redirect = TRUE, $redirect_to_file = FALSE, $destination_path_override = NULL) {
  if (isset($destination_path_override) && empty($destination_path_override) !== FALSE) {
    $destination_path = $destination_path_override;
  }
  if (empty($pdf_info->destination_path) && empty($destination_path_override)) {

    // If this function is called and the PDF isn't set up with a destination
    // path, give it one.
    $destination_path = 'fillpdf';
  }
  else {
    $destination_path = $pdf_info->destination_path;
  }
  $destination_path = _fillpdf_process_destination_path($pdf_info->destination_path, $token_objects);
  $path_exists = file_prepare_directory($destination_path, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS);
  if ($path_exists === FALSE) {
    watchdog('fillpdf', "The path %destination_path does not exist and could not be\n      automatically created. Therefore, the previous submission was not saved. If\n      the URL contained download=1, then the PDF was still sent to the user's browser.\n      If you were redirecting them to the PDF, they were sent to the homepage instead.\n      If the destination path looks wrong and you have used tokens, check that you have\n      used the correct token and that it is available to FillPDF at the time of PDF\n      generation.", array(
      '%destination_path' => $destination_path,
    ));
  }
  else {

    // Full steam ahead!
    $saved_file_path = file_unmanaged_save_data($pdf_data, $destination_path . "/{$output_name}", FILE_EXISTS_RENAME);
    if ($redirect === TRUE) {
      if (isset($_GET['destination']) === FALSE) {

        // Should we send the user directly to the saved PDF? If so, do that.
        if ($redirect_to_file) {
          drupal_goto(file_create_url($saved_file_path));
        }
      }
    }
  }
  if ($redirect === TRUE) {

    // Allow the "destination" query string parameter to be used
    // e.g. fillpdf?nid=1&fid=1&destination=node/1
    // If no destination is provided, drupal_goto() will send the
    // user to the front page.
    drupal_goto();
  }
  return $saved_file_path;
}