You are here

function print_ui_node_view_alter in Printer, email and PDF versions 7.2

Implements hook_node_view_alter().

File

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

Code

function print_ui_node_view_alter(&$build) {
  if (isset($build['links']['book']['#links']['book_printer'])) {
    $book_link = variable_get('print_html_book_link', PRINT_UI_BOOK_LINK_DEFAULT);
    if ($book_link) {
      $link = print_print_link();
      $link_pos = variable_get('print_html_link_pos', drupal_json_decode(PRINT_UI_LINK_POS_DEFAULT));
      if (!empty($link_pos['link'])) {
        $format = theme('print_ui_format_link', array(
          'format' => 'html',
          'location' => 'link',
        ));
        $path = '';
        switch ($book_link) {
          case 1:
            $path = $build['links']['book']['#links']['book_printer']['href'];
            break;
          case 2:
            $link_use_alias = variable_get('print_html_link_use_alias', PRINT_UI_LINK_USE_ALIAS_DEFAULT);
            $path = $link_use_alias && ($alias = drupal_lookup_path('alias', 'node/' . $build['#node']->nid)) ? $alias : $build['#node']->nid;
            break;
        }
        $build['links']['book']['#links']['book_printer'] = array(
          'href' => $link['path'] . '/' . $path,
          'title' => $format['text'],
          'attributes' => $format['attributes'],
          'html' => $format['html'],
        );
      }
      else {
        unset($build['links']['book']['#links']['book_printer']);
      }
    }
  }
}