You are here

function facebook_pixel_entity_view in Facebook Pixel 8

Implements hook_entity_view().

File

./facebook_pixel.module, line 89
Contains facebook_pixel.module..

Code

function facebook_pixel_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  $facebook_event = \Drupal::service('facebook_pixel.facebook_event');
  if ($entity
    ->getEntityType()
    ->id() == 'node' && in_array($view_mode, [
    'default',
    'full',
  ])) {

    /** @var \Drupal\node\NodeInterface $entity */
    $data = [
      'content_name' => $entity
        ->getTitle(),
      'content_type' => $entity
        ->getType(),
      'content_ids' => [
        $entity
          ->id(),
      ],
    ];
    $facebook_event
      ->addEvent('ViewContent', $data);
  }
}