Commit d6dd49de authored by jcnventura's avatar jcnventura

Issue #1579954 by jorisdejong: Add drupal_alter for PDF filename.

parent 07f11643
......@@ -31,6 +31,15 @@
* @ingroup print_hooks
*/
function hook_print_pdf_generate($html, $meta, $filename = NULL) {
$pdf = new PDF();
$pdf->writeHTML($html);
if ($filename) {
$pdf->Output($filename);
return TRUE;
}
else {
return $pdf->Output();
}
}
/**
......@@ -42,7 +51,7 @@ function hook_print_pdf_generate($html, $meta, $filename = NULL) {
* and the libraries directory in search of the unique file pattern that can
* be used to identify the library location.
*
* @param array pdf_tools
* @param array $pdf_tools
* An associative array using as key the format 'module|path', and as value
* a string describing the discovered library, where:
* - module: the machine name of the module that handles this library.
......@@ -62,6 +71,24 @@ function hook_print_pdf_available_libs_alter(&$pdf_tools) {
}
}
/**
* Alters the PDF filename.
*
* Changes the value of the PDF filename variable, just before it is used to
* create the file. When altering the variable, do not suffix it with the
* '.pdf' extension, as the module will do that automatically.
*
* @param string $pdf_filename
* current value of the pdf_filename variable, after processing tokens and
* any transliteration steps.
* @param string $path
* original alias/system path of the page being converted to PDF.
* @ingroup print_hooks
*/
function hook_print_pdf_filename_alter(&$pdf_filename, &$path) {
$pdf_filename = 'foo';
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -38,14 +38,13 @@ function print_pdf_controller() {
$node = node_load($args[0]);
}
// @todo fix this for empty pdf_filenames
$pdf_filename = variable_get('print_pdf_filename', PRINT_PDF_FILENAME_DEFAULT);
if (!empty($pdf_filename) && !empty($node)) {
$pdf_filename = token_replace($pdf_filename, array('node' => $node));
}
else {
$pdf_filename = token_replace($pdf_filename, array('site'));
if (count(token_scan($pdf_filename))) {
if (empty($pdf_filename) || count(token_scan($pdf_filename))) {
// If there are still tokens, use a fallback solution
$pdf_filename = str_replace('/', '_', $path);
}
......@@ -59,6 +58,8 @@ function print_pdf_controller() {
$pdf_filename = transliteration_clean_filename($pdf_filename, language_default('language'));
}
drupal_alter('print_pdf_filename', $pdf_filename, $path);
$pdf = print_pdf_generate_path($path, $cid, $pdf_filename . '.pdf');
if ($pdf == NULL) {
drupal_goto($path);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment