You are here

forena_pdf.module in Forena Reports 8

Forena pdf generation module @author metzlerd

File

forena_pdf/forena_pdf.module
View source
<?php

/**
 * @file
 * Forena pdf generation module
 * @author metzlerd
 */

/**
 * Implementation of hook_menu
 */
function forena_pdf_menu() {
  $items = array();
  $items['admin/config/content/forena/pdf'] = array(
    'title' => 'PDF',
    'type' => MENU_LOCAL_TASK,
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'forena_pdf_configure',
    ),
    'access arguments' => array(
      'administer forena reports',
    ),
  );
  return $items;
}

/**
 * Implementation of hook_forena_document_types
 */
function forena_pdf_forena_document_types() {

  //require_once 'docformats/PDF.inc';
  $items = array();
  $pdf_generator = \Drupal::config('forena.settings')
    ->get('forena_pdf_generator');
  if ($pdf_generator) {
    include_once 'docformats/' . $pdf_generator . '.inc';
    $items['pdf'] = array(
      'class' => $pdf_generator,
      'title' => t('PDF Document'),
    );
  }
  return $items;
}

/**
 * Implementation of configuration form.
 * @param array $form
 * @param \Drupal\Core\Form\FormStateInterface $form_state
 * @return $form 
 *   Form eelements for pdf configuraiton. 
 */
function forena_pdf_configure($form, &$form_state) {
  $path = \Drupal::config('forena.settings')
    ->get('forena_pdf_prince_path');
  $disable_links = \Drupal::config('forena.settings')
    ->get('forena_pdf_disable_links');
  $pdf_options = array(
    '' => t('None'),
    'PDF' => t('Prince XML'),
    'MPDF' => t('MPDF'),
  );
  $pdf_generator = \Drupal::config('forena.settings')
    ->get('forena_pdf_generator');
  $mpdf_path = t('MDPF Libarary not found. Please install so sites/all/libraries/mpdf/mpdf.php exists.');
  if (forena_library_file('mpdf')) {
    $mpdf_path = 'sites/all/libraries/mpdf';
  }
  else {
    unset($pdf_options['MPDF']);
  }
  $prince_path = t('Prince XML library not found.  Please install so sites/all/libraries/prince/prince.php exists.');
  if (forena_library_file('prince')) {
    $prince_path = 'sites/all/libraries/prince';
  }
  else {
    unset($pdf_options['PDF']);
  }
  $form['forena_pdf_generator'] = array(
    '#type' => 'select',
    '#title' => t('PDF Generation Method'),
    '#options' => $pdf_options,
    '#default_value' => $pdf_generator,
  );
  $form['forena_pdf_disable_links'] = array(
    '#type' => 'checkbox',
    '#title' => 'Disable links in PDF Documents',
    '#description' => t('When checked links in reports will not appear as links in PDF documents.'),
    '#default_value' => $disable_links,
  );
  $form['mpdf'] = array(
    '#type' => 'fieldset',
    '#title' => t('MPDF library'),
  );
  $form['mpdf']['library'] = array(
    '#type' => 'item',
    '#title' => 'Installation path',
    '#markup' => $mpdf_path,
  );
  $form['prince'] = array(
    '#type' => 'fieldset',
    '#title' => t('Prince XML'),
  );
  $form['prince']['library'] = array(
    '#type' => 'item',
    '#title' => 'PHP Library path',
    '#markup' => $prince_path,
  );
  $form['prince']['forena_pdf_prince_path'] = array(
    '#type' => 'textfield',
    '#title' => 'Path to binary',
    '#description' => t('Specify the location of the prince executable (e.g. /usr/local/bin/prince'),
    '#required' => TRUE,
    '#default_value' => $path,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Save',
  );
  return $form;
}
function forena_pdf_configure_submit($form, &$form_state) {
  \Drupal::config('forena.settings')
    ->set('forena_pdf_generator', $form_state['values']['forena_pdf_generator']);
  \Drupal::config('forena.settings')
    ->set('forena_pdf_prince_path', $form_state['values']['forena_pdf_prince_path']);
  \Drupal::config('forena.settings')
    ->set('forena_pdf_disable_links', $form_state['values']['forena_pdf_disable_links']);
  \Drupal::config('forena.settings')
    ->save();
  drupal_set_message(t('Options Saved'));
}

Functions

Namesort descending Description
forena_pdf_configure Implementation of configuration form.
forena_pdf_configure_submit
forena_pdf_forena_document_types Implementation of hook_forena_document_types
forena_pdf_menu Implementation of hook_menu