You are here

function print_ui_form_alter in Printer, email and PDF versions 7.2

Implements hook_form_alter().

File

print_ui/print_ui.module, line 391
Printer-friendly pages User Interface module.

Code

function print_ui_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' || !empty($form['#node_edit_form']))) {
    $form['print'] = array(
      '#type' => 'fieldset',
      '#title' => t('Printer, email and PDF versions'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
      '#weight' => PRINT_UI_TYPE_FIELDS_WEIGHT,
      '#group' => 'additional_settings',
    );
    foreach (module_implements('print_link') as $module) {
      $function = $module . '_print_link';
      if (function_exists($function)) {
        $link = call_user_func_array($function, array());
        $form['print']['print_' . $link['format']] = array(
          '#type' => 'fieldset',
          '#title' => check_plain($link['text']),
          '#collapsible' => TRUE,
        );
        $display = 'print_' . $link['format'] . '_display';
        $display_comment = 'print_' . $link['format'] . '_display_comment';
        $display_urllist = 'print_' . $link['format'] . '_display_urllist';
        $form['print']['print_' . $link['format']][$display] = array(
          '#type' => 'checkbox',
          '#title' => t('Show link'),
        );
        $form['print']['print_' . $link['format']][$display_comment] = array(
          '#type' => 'checkbox',
          '#title' => t('Show link in individual comments'),
        );
        $form['print']['print_' . $link['format']][$display_urllist] = array(
          '#type' => 'checkbox',
          '#title' => t('Show Printer-friendly URLs list'),
        );
        if ($form_id == 'node_type_form') {
          $form['print']['print_' . $link['format']][$display]['#default_value'] = variable_get($display . '_' . $form['#node_type']->type, PRINT_UI_TYPE_SHOW_LINK_DEFAULT);
          $form['print']['print_' . $link['format']][$display_comment]['#default_value'] = variable_get($display_comment . '_' . $form['#node_type']->type, PRINT_UI_TYPE_COMMENT_LINK_DEFAULT);
          $form['print']['print_' . $link['format']][$display_urllist]['#default_value'] = variable_get($display_urllist . '_' . $form['#node_type']->type, PRINT_TYPE_URLLIST_DEFAULT);
        }
        else {
          $node = $form['#node'];
          $form['print']['print_' . $link['format']][$display]['#default_value'] = isset($node->{$display}) ? $node->{$display} : variable_get($display . '_' . $node->type, PRINT_UI_TYPE_SHOW_LINK_DEFAULT);
          $form['print']['print_' . $link['format']][$display_comment]['#default_value'] = isset($node->{$display_comment}) ? $node->{$display_comment} : variable_get($display_comment . '_' . $node->type, PRINT_UI_TYPE_COMMENT_LINK_DEFAULT);
          $form['print']['print_' . $link['format']][$display_urllist]['#default_value'] = isset($node->{$display_urllist}) ? $node->{$display_urllist} : variable_get($display_urllist . '_' . $node->type, PRINT_TYPE_URLLIST_DEFAULT);
        }
      }
    }
  }
}