You are here

function like_and_dislike_entity_view in Like & Dislike 8

Same name and namespace in other branches
  1. 7 like_and_dislike.module \like_and_dislike_entity_view()

Renders the like/dislike buttons if the user has permission to see it.

File

./like_and_dislike.module, line 78
This module provides 2 voting widgets: Like and Dislike.

Code

function like_and_dislike_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {

  // If we are in preview mode we don't have the $entity->id().
  if (!$display
    ->getComponent('like_and_dislike') || !$entity
    ->id()) {
    return;
  }
  if (like_and_dislike_is_enabled($entity)) {
    $entity_type_id = $entity
      ->getEntityTypeId();
    $entity_id = $entity
      ->id();
    $build['like_and_dislike'] = [
      '#lazy_builder' => [
        'like_and_dislike.vote_builder:build',
        [
          $entity_type_id,
          $entity_id,
        ],
      ],
      '#create_placeholder' => TRUE,
    ];
  }
}