You are here

function social_simple_node_view in Social simple 8

Same name and namespace in other branches
  1. 2.0.x social_simple.module \social_simple_node_view()

Implements hook_entity_view().

File

./social_simple.module, line 88
Contains social.module..

Code

function social_simple_node_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($display
    ->getComponent('social_simple_buttons')) {

    /** @var \Drupal\node\NodeInterface $entity */

    // Support social simple per node feature.
    if ($entity
      ->hasField('social_share')) {
      if ($entity->social_share->value !== NULL && empty($entity->social_share->value)) {
        return;
      }
    }

    /** @var \Drupal\social_simple\SocialSimpleGenerator $social_simple_generator */
    $social_simple_generator = \Drupal::service('social_simple.generator');

    /** @var \Drupal\node\NodeTypeInterface $node_type */
    $node_type = $entity->type->entity;
    $share = $node_type
      ->getThirdPartySetting('social_simple', 'share', 0);
    $networks = $node_type
      ->getThirdPartySetting('social_simple', 'networks', []);
    if ($share && !empty($networks)) {
      $title = $node_type
        ->getThirdPartySetting('social_simple', 'title', '');
      $build['social_simple_buttons'] = $social_simple_generator
        ->buildSocialLinks($networks, $title, $entity);
    }
  }
}