You are here

vde_pdf_wkhtmltopdf.module in Views Data Export PDF 7.2

Same filename and directory in other branches
  1. 7 modules/vde_pdf_wkhtmltopdf/vde_pdf_wkhtmltopdf.module

File

modules/vde_pdf_wkhtmltopdf/vde_pdf_wkhtmltopdf.module
View source
<?php

/**
 * @file
 * Functions and hooks for the Views Data Export PDF - Renderer: wkhtmltopdf
 * module.
 */
require_once 'vde_pdf_wkhtmltopdf.theme.inc';

/**
 * The default path to WK HTML to PDF on most systems.
 */
define('VIEWS_DATA_EXPORT_DEFAULT_WKHTMLTOPDF_BINARY_PATH', '/usr/local/bin/wkhtmltopdf');

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Alters the VDE PDF settings form to add a wkhtmltopdf path setting.
 */
function vde_pdf_wkhtmltopdf_form_views_data_export_pdf_settings_form_alter(array &$form) {
  $form['views_data_export_pdf_wkhtmltopdf'] = array(
    '#type' => 'textfield',
    '#title' => t('wkhtmltopdf Location'),
    '#description' => t('Set this to the system path where WkHtmlToPdf is located.'),
    '#default_value' => vde_pdf_wkhtmltopdf_get_wkhtmltopdf_path(),
  );
}

/**
 * Implements hook_pdf_export_renderers().
 */
function vde_pdf_wkhtmltopdf_pdf_export_renderers() {
  $renderers = [];
  $renderers['wkhtmltopdf_in_proc'] = [
    'title' => t('wkhtmltopdf (In-process, blocking)'),
    'description' => t('Invokes <code>wkhtmltopdf</code> within the request and blocks further processing of that request until the PDF has been generated.'),
    'class' => 'views_data_export_pdf_wkhtmltopdf_in_proc_renderer',
    'file' => 'src/views_data_export_pdf_wkhtmltopdf_in_proc_renderer.inc',
  ];
  if (module_exists('vde_pdf_background_process')) {

    // This renderer wraps the in-proc renderer in a background process renderer
    $renderers['wkhtmltopdf_background_process'] = [
      'title' => t('wkhtmltopdf (Background process, async)'),
      'description' => t('During batched exports, invokes <code>wkhtmltopdf</code> in an asynchronous background process to avoid load balancer timeouts on large data sets.'),
      'class' => 'views_data_export_pdf_background_process_renderer',
      'file' => 'src/views_data_export_pdf_background_process_renderer.inc',
      'file path' => drupal_get_path('module', 'vde_pdf_background_process'),
      'constructor arguments' => [
        'vde_pdf_wkhtmltopdf',
        'views_data_export_pdf_wkhtmltopdf_in_proc_renderer',
      ],
    ];
  }
  return $renderers;
}

/**
 * Gets the path of this module relative to the site base.
 *
 * @return string
 */
function vde_pdf_wkhtmltopdf_get_module_path() {
  return drupal_get_path('module', 'vde_pdf_wkhtmltopdf');
}

/**
 * Gets the configured path to the WK HTML to PDF binary.
 *
 * @return string
 */
function vde_pdf_wkhtmltopdf_get_wkhtmltopdf_path() {
  return variable_get('views_data_export_pdf_wkhtmltopdf', VIEWS_DATA_EXPORT_DEFAULT_WKHTMLTOPDF_BINARY_PATH);
}

/**
 * Returns the relative URL to the common JS for PDF headers and footers.
 *
 * NOTE: This JavaScript is not run through Drupal's normal #attached JS
 * mechanism because it is rendered manually through the header HTML and footer
 * HTML templates.
 *
 * @return string
 *   The URL of the script.
 */
function vde_pdf_wkhtmltopdf_get_header_footer_js_path() {
  $module_path = vde_pdf_wkhtmltopdf_get_module_path();

  /** @noinspection PhpUnnecessaryLocalVariableInspection */
  $js_path = sprintf('%s/js/wkhtmltopdf_header_footer.js', $module_path);
  return $js_path;
}

Functions

Namesort descending Description
vde_pdf_wkhtmltopdf_form_views_data_export_pdf_settings_form_alter Implements hook_form_FORM_ID_alter().
vde_pdf_wkhtmltopdf_get_header_footer_js_path Returns the relative URL to the common JS for PDF headers and footers.
vde_pdf_wkhtmltopdf_get_module_path Gets the path of this module relative to the site base.
vde_pdf_wkhtmltopdf_get_wkhtmltopdf_path Gets the configured path to the WK HTML to PDF binary.
vde_pdf_wkhtmltopdf_pdf_export_renderers Implements hook_pdf_export_renderers().

Constants

Namesort descending Description
VIEWS_DATA_EXPORT_DEFAULT_WKHTMLTOPDF_BINARY_PATH The default path to WK HTML to PDF on most systems.