You are here

function bbb_node_node_view in BigBlueButton 8

Implements hook_ENTITY_TYPE_view().

File

modules/bbb_node/bbb_node.module, line 251
Big Blue Button - Enables universities and colleges to deliver a high-quality learning experience.

Code

function bbb_node_node_view(array &$build, EntityInterface $node, EntityViewDisplayInterface $display, $view_mode) {

  /** @var \Drupal\bbb_node\Service\NodeMeeting $node_meeting */
  $node_meeting = \Drupal::service('bbb_node.meeting');

  /** @var \Drupal\node\NodeInterface $node */
  $node_type = $node
    ->getType();
  if (!$node_meeting
    ->isTypeOf($node)) {
    return;
  }
  $meeting = $node_meeting
    ->get($node);
  $BBBNodeTypeConfig = \Drupal::entityTypeManager()
    ->getStorage('bbb_node_type')
    ->load($node
    ->getType());

  // Show meeting status.
  if ($BBBNodeTypeConfig
    ->get('showStatus')) {
    $build['content']['bbb_meeting_status'] = [
      '#theme' => 'bbb_meeting_status',
      '#meeting' => $meeting,
      '#weight' => 10,
    ];
    $build['content']['bbb_meeting_record'] = [
      '#theme' => 'bbb_meeting_record',
      '#meeting' => $meeting,
      '#weight' => 11,
    ];
  }

  // Add links to content.
  $links = [];
  $show = $BBBNodeTypeConfig
    ->get('showLinks');
  if ($view_mode !== 'teaser' && $show) {
    $meeting = $node_meeting
      ->get($node);
    $current_user = \Drupal::currentUser();
    if ($current_user
      ->hasPermission('bbb_node attend meetings') || $current_user
      ->hasPermission('administer big blue button')) {
      $links['meeting_attend'] = [
        'title' => t('Attend meeting'),
        'href' => Url::fromRoute('bbb_node.meeting.attend', [
          'node' => $node
            ->id(),
        ])
          ->toString(),
      ];
    }
    if (\Drupal::currentUser()
      ->hasPermission('bbb_node moderate meetings') || $current_user
      ->hasPermission('administer big blue button') || $current_user
      ->id() == $node
      ->getAuthor()
      ->id() && $current_user
      ->hasPermission('bbb_node moderate own meetings')) {
      $links['meeting_moderate'] = [
        'title' => t('Moderate meeting'),
        'href' => Url::fromRoute('bbb_node.meeting.moderate', [
          'node' => $node
            ->id(),
        ])
          ->toString(),
      ];
    }
    if ($current_user
      ->hasPermission('bbb_node moderate meetings') || $current_user
      ->hasPermission('administer big blue button') || $current_user
      ->id() == $node
      ->getAuthor()
      ->id() && $current_user
      ->hasPermission('bbb_node moderate own meetings') && $meeting['info']
      ->isRunning()) {
      $links['meeting_end'] = [
        'title' => t('Terminate meeting'),
        'href' => Url::fromRoute('bbb_node.meeting.end_meeting_confirm_form', [
          'node' => $node
            ->id(),
        ])
          ->toString(),
      ];
    }
    if (!empty($links)) {
      $build['content']['links']['bbb'] = [
        '#links' => $links,
      ];
    }
  }
}