You are here

function entity_print_entity_view_alter in Entity Print 8

Same name and namespace in other branches
  1. 8.2 entity_print.module \entity_print_entity_view_alter()

Implements hook_entity_view_alter().

File

./entity_print.module, line 50
Print any entity.

Code

function entity_print_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
  if ($display
    ->getComponent('entity_print_view')) {
    $route_params = [
      'entity_type' => $entity
        ->getEntityTypeId(),
      'entity_id' => $entity
        ->id(),
    ];
    $build['entity_print_view'] = Link::createFromRoute($display
      ->getThirdPartySetting('entity_print', 'label', t('View PDF')), 'entity_print.view', $route_params)
      ->toRenderable();

    // Add the access control.
    $build['entity_print_view']['#access'] = \Drupal::accessManager()
      ->checkNamedRoute('entity_print.view', $route_params);
  }
}