You are here

function print_pdf_form_alter in Printer, email and PDF versions 7.2

Same name and namespace in other branches
  1. 5.4 print_pdf/print_pdf.module \print_pdf_form_alter()
  2. 5.3 print_pdf/print_pdf.module \print_pdf_form_alter()
  3. 6 print_pdf/print_pdf.module \print_pdf_form_alter()
  4. 7 print_pdf/print_pdf.module \print_pdf_form_alter()
  5. 5.x print_pdf/print_pdf.module \print_pdf_form_alter()

Implements hook_form_alter().

File

print_pdf/print_pdf.module, line 269
Displays Printer-friendly versions of Drupal pages.

Code

function print_pdf_form_alter(&$form, &$form_state, $form_id) {

  // Add the node-type settings to activate the printer-friendly version link.
  if ((user_access('administer print') || user_access('node-specific print configuration')) && ($form_id == 'node_type_form' || !empty($form['#node_edit_form']))) {
    $link = print_pdf_print_link();
    $size = 'print_' . $link['format'] . '_size';
    $orientation = 'print_' . $link['format'] . '_orientation';
    $form['print']['print_' . $link['format']][$size] = array(
      '#type' => 'select',
      '#title' => t('Paper size'),
      '#options' => _print_pdf_paper_sizes(TRUE),
      '#description' => t('Choose the paper size of the generated PDF.'),
    );
    $form['print']['print_' . $link['format']][$orientation] = array(
      '#type' => 'select',
      '#title' => t('Page orientation'),
      '#options' => array(
        '' => 'Unchanged',
        'portrait' => t('Portrait'),
        'landscape' => t('Landscape'),
      ),
      '#description' => t('Choose the page orientation of the generated PDF.'),
    );
    if ($form_id == 'node_type_form') {
      $form['print']['print_' . $link['format']][$size]['#default_value'] = variable_get($size . '_' . $form['#node_type']->type);
      $form['print']['print_' . $link['format']][$orientation]['#default_value'] = variable_get($orientation . '_' . $form['#node_type']->type);
    }
    else {
      $node = $form['#node'];
      $form['print']['print_' . $link['format']][$size]['#default_value'] = isset($node->{$size}) ? $node->{$size} : variable_get($size . '_' . $node->type);
      $form['print']['print_' . $link['format']][$orientation]['#default_value'] = isset($node->{$orientation}) ? $node->{$orientation} : variable_get($orientation . '_' . $node->type);
    }
  }
}