You are here

function printfriendly_node_view in PrintFriendly & PDF 7.5

Same name and namespace in other branches
  1. 8.3 printfriendly.module \printfriendly_node_view()
  2. 8 printfriendly.module \printfriendly_node_view()
  3. 8.2 printfriendly.module \printfriendly_node_view()
  4. 7 printfriendly.module \printfriendly_node_view()
  5. 7.2 printfriendly.module \printfriendly_node_view()
  6. 7.3 printfriendly.module \printfriendly_node_view()
  7. 7.4 printfriendly.module \printfriendly_node_view()

Implements hook_node_view().

File

./printfriendly.module, line 143
Adds PrintFriendly button to chosen node types and provides a block.

Code

function printfriendly_node_view($node, $view_mode) {
  if (in_array($view_mode, array_filter(variable_get('printfriendly_display', array(
    'full',
  ))))) {
    if (in_array($node->type, variable_get('printfriendly_types', array()), TRUE) && user_access('access printfriendly')) {
      if ($view_mode == 'teaser') {
        $block = printfriendly_create_button('node/' . $node->nid, FALSE);
      }
      else {
        $block = printfriendly_create_button();
        foreach ($block['#attached']['js'] as $key => $value) {
          drupal_add_js($key, $value);
        }
      }
      $links['printfriendly'] = array(
        'title' => $block['#markup'],
        'attributes' => array(
          'class' => array(
            'printfriendly-node',
            $node->type,
          ),
        ),
        'html' => TRUE,
      );
      $node->content['links']['printfriendly'] = array(
        '#theme' => 'links',
        '#links' => $links,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      );
    }
  }
}