You are here

function printfriendly_node_view in PrintFriendly & PDF 8.3

Same name and namespace in other branches
  1. 8 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 139
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');
  $config_display = $config
    ->get('printfriendly_display', array(
    'full',
  ));
  if (!is_array($config_display)) {
    $config_display = [];
  }
  if (in_array($node
    ->getType(), array_filter($config_display)) && \Drupal::currentUser()
    ->hasPermission('access printfriendly')) {
    if ($view_mode == 'teaser' && in_array($view_mode, array_filter($config_display))) {
      $block = printfriendly_create_button('/node/' . $node
        ->id(), FALSE);
      $build['printfriendly'] = [
        '#markup' => $block['#markup'],
        '#attributes' => [
          'class' => [
            'links',
            'inline',
            'printfriendly-node',
            $node
              ->getType(),
          ],
        ],
      ];
    }
    elseif ($view_mode != 'teaser') {
      $block = printfriendly_create_button();
      $build['printfriendly'] = [
        '#markup' => $block['#markup'],
        '#attributes' => [
          'class' => [
            'links',
            'inline',
            'printfriendly-node',
            $node
              ->getType(),
          ],
        ],
      ];
    }
  }
}