You are here

function forward_entity_view in Forward 8

Same name and namespace in other branches
  1. 8.3 forward.module \forward_entity_view()
  2. 8.2 forward.module \forward_entity_view()
  3. 7.3 forward.module \forward_entity_view()

Implements hook_entity_view().

File

./forward.module, line 57
Allows forwarding of entities by email.

Code

function forward_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  $settings = \Drupal::config('forward.settings')
    ->get();

  // Let hook_node_links_alter handle Forward inline links on nodes
  if ($settings['forward_link_inline'] && $settings['forward_interface_type'] == 'link' && $entity
    ->getEntityTypeId() == 'node') {
    return;
  }

  // Display a forward link or form unless the entity is being rendered for a forward email
  $show = \Drupal::service('forward.access_checker')
    ->isAllowed($settings, $entity, $view_mode) && empty($build['#forward_build']);
  if ($show) {
    if ($settings['forward_interface_type'] == 'link') {
      $build['forward'] = \Drupal::service('forward.link_builder')
        ->buildForwardEntityLink($entity, $settings);
    }
    else {
      $build['forward'] = \Drupal::service('forward.form_builder')
        ->buildForwardEntityForm($entity, $settings);
    }
  }
}