You are here

function print_form_alter in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 5.4 print.module \print_form_alter()
  2. 5 print.module \print_form_alter()
  3. 5.2 print.module \print_form_alter()
  4. 5.3 print.module \print_form_alter()
  5. 7 print.module \print_form_alter()
  6. 5.x print.module \print_form_alter()

Implementation of hook_form_alter().

File

./print.module, line 482
Displays Printer-friendly versions of Drupal pages.

Code

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

  // Add the node-type settings option to activate the printer-friendly version link
  if ((user_access('administer print') || user_access('node-specific print configuration')) && ($form_id == 'node_type_form' || isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id)) {
    $form['print'] = array(
      '#type' => 'fieldset',
      '#title' => t('Printer, email and PDF versions'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => function_exists('content_extra_field_weight') && isset($form['type']) ? content_extra_field_weight($form['type']['#value'], 'print') : PRINT_TYPE_FIELDS_WEIGHT,
      '#group' => 'additional_settings',
    );
    $form['print']['label'] = array(
      '#type' => 'markup',
      '#value' => '<p><strong>' . t('Printer-friendly version') . '</strong></p>',
    );
    $form['print']['print_display'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show link'),
    );
    $form['print']['print_display_comment'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show link in individual comments'),
    );
    $form['print']['print_display_urllist'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show Printer-friendly URLs list'),
    );
    if ($form_id == 'node_type_form') {
      $form['print']['print_display']['#default_value'] = variable_get('print_display_' . $form['#node_type']->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
      $form['print']['print_display_comment']['#default_value'] = variable_get('print_display_comment_' . $form['#node_type']->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
      $form['print']['print_display_urllist']['#default_value'] = variable_get('print_display_urllist_' . $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT);
    }
    else {
      $node = $form['#node'];
      $form['print']['print_display']['#default_value'] = isset($node->print_display) ? $node->print_display : variable_get('print_display_' . $node->type, PRINT_TYPE_SHOW_LINK_DEFAULT);
      $form['print']['print_display_comment']['#default_value'] = isset($node->print_display_comment) ? $node->print_display_comment : variable_get('print_display_comment_' . $node->type, PRINT_TYPE_COMMENT_LINK_DEFAULT);
      $form['print']['print_display_urllist']['#default_value'] = isset($node->print_display_urllist) ? $node->print_display_urllist : variable_get('print_display_urllist_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
    }
  }
}