You are here

function printfriendly_node_view in PrintFriendly & PDF 8

Same name and namespace in other branches
  1. 8.3 printfriendly.module \printfriendly_node_view()
  2. 8.2 printfriendly.module \printfriendly_node_view()
  3. 7.5 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()

File

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

Code

function printfriendly_node_view(array &$build, NodeInterface $node, EntityViewDisplayInterface $display, $view_mode) {
  $config = \Drupal::config('printfriendly.settings');
  if (in_array($view_mode, array_filter($config
    ->get('printfriendly_display', array(
    'full',
  ))))) {
    if (in_array($node
      ->getType(), $config
      ->get('printfriendly_types', array()), TRUE) && \Drupal::currentUser()
      ->hasPermission('access printfriendly')) {
      if ($view_mode == 'teaser') {
        $block = printfriendly_create_button('/node/' . $node
          ->id(), FALSE);
      }
      else {
        $block = printfriendly_create_button();
      }
      $build['printfriendly'] = array(
        '#markup' => $block['#markup'],
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
            'printfriendly-node',
            $node
              ->getType(),
          ),
        ),
      );
    }
  }
}