You are here

public function LearningPathController::trainingContentForum in Opigno Learning path 3.x

Training forum block.

1 call to LearningPathController::trainingContentForum()
LearningPathController::trainingContent in src/Controller/LearningPathController.php
Training content.

File

src/Controller/LearningPathController.php, line 539

Class

LearningPathController
Class LearningPathController.

Namespace

Drupal\opigno_learning_path\Controller

Code

public function trainingContentForum(&$content, $group, $user) {
  $has_enable_forum_field = $group
    ->hasField('field_learning_path_enable_forum');
  $has_forum_field = $group
    ->hasField('field_learning_path_forum');
  if ($has_enable_forum_field && $has_forum_field) {
    $enable_forum_field = $group
      ->get('field_learning_path_enable_forum')
      ->getValue();
    $forum_field = $group
      ->get('field_learning_path_forum')
      ->getValue();
    if (!empty($enable_forum_field) && !empty($forum_field)) {
      $enable_forum = $enable_forum_field[0]['value'];
      $forum_tid = $forum_field[0]['target_id'];
      if ($enable_forum && _opigno_forum_access($forum_tid, $user)) {
        $forum_url = Url::fromRoute('forum.page', [
          'taxonomy_term' => $forum_tid,
        ])
          ->toString();
        $content['tabs'][] = $forum_url = [
          '#markup' => '<div class="see-all"><a href="' . $forum_url . '">' . $this
            ->t('See all') . '</a></div>',
        ];
        $block_render = $this
          ->attachBlock('opigno_forum_last_topics_block', [
          'taxonomy_term' => $forum_tid,
        ]);
        $block_render["content"]['link'] = $forum_url;
        $content['tab_content']['forum'] = $block_render["topics"] ? [
          '#type' => 'container',
          '#attributes' => [
            'id' => 'forum',
          ],
          'block' => [
            'content' => $block_render["content"],
          ],
        ] : [];
      }
    }
  }
  return $content;
}