You are here

public function LearningPathProgressBlock::build in Opigno module 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Block/LearningPathProgressBlock.php \Drupal\opigno_module\Plugin\Block\LearningPathProgressBlock::build()

Throws

\Exception

Overrides BlockPluginInterface::build

File

src/Plugin/Block/LearningPathProgressBlock.php, line 26

Class

LearningPathProgressBlock
Provides a 'LearningPathProgressBlock' block.

Namespace

Drupal\opigno_module\Plugin\Block

Code

public function build() {
  if (!opigno_module_is_activity_route()) {
    return [];
  }
  $build = [];
  $home_link = NULL;
  $user = \Drupal::currentUser();
  $progress = 0;
  if ($gid = OpignoGroupContext::getCurrentGroupId()) {
    if ($group = \Drupal::entityTypeManager()
      ->getStorage('group')
      ->load($gid)) {
      $home_link = Link::createFromRoute(t('home'), 'entity.group.canonical', [
        'group' => $group
          ->id(),
      ], [
        'attributes' => [
          'class' => [
            'w-100',
          ],
        ],
      ])
        ->toRenderable();
      $home_link = render($home_link);
    }
  }
  if ($user && isset($group)) {
    $progress_service = \Drupal::service('opigno_learning_path.progress');
    $progress = $progress_service
      ->getProgressAjaxContainer($gid, $user
      ->id(), '', 'module-page');
    $progress = render($progress);
  }
  $build = [
    'home_link' => $home_link,
    'progress' => $progress,
    'ajax_conteiner' => TRUE,
  ];
  return $build;
}