You are here

function area_print_form in Area Print 7

Same name and namespace in other branches
  1. 6 area_print.module \area_print_form()

Implements hook_form().

Parameters

$options: An associative array containing: (optional) target_id: Id of the element you want to print, (optional) button_id: Id that will be given to the print link or button, (optional) value: The text for the link/button, eg. t('Print'), (optional) type: either 'link' or 'button', (optional) custom_css: path to a css file that will get added to the page before printing, eg. drupal_get_path('module','my_module').'/css/print.css'

Return value

Returns the rendered HTML for the print button/link.

File

./area_print.module, line 22
Area Print module-file.

Code

function area_print_form($options = array()) {
  $default_options = array(
    'button_id' => 'area_print_button',
    'target_id' => 'content',
    'value' => t('Print'),
    'type' => 'button',
    'hide_button' => FALSE,
    'custom_css' => 'none',
  );
  $options = array_merge($default_options, $options);
  $js_options[$options['button_id']] = array(
    'button_id' => $options['button_id'],
    'target_id' => $options['target_id'],
    'custom_css' => $options['custom_css'],
    'hide_button' => $options['hide_button'],
  );
  drupal_add_js(array(
    'area_print' => $js_options,
  ), 'setting');
  $form['#attached']['js'] = array(
    drupal_get_path('module', 'area_print') . '/area_print.js',
  );
  switch ($options['type']) {
    case 'button':
      $form['print_button'] = array(
        '#attributes' => array(
          'class' => array(
            'area-print-trigger',
          ),
        ),
        '#id' => $options['button_id'],
        '#type' => 'button',
        '#value' => $options['value'],
      );
      break;
    case 'link':
      $form['print_link'] = array(
        '#attributes' => array(
          'class' => array(
            'area-print-trigger',
          ),
        ),
        '#id' => $options['button_id'],
        '#type' => 'link',
        '#title' => $options['value'],
        '#href' => '',
      );
      break;
  }
  return drupal_render($form);
}