public function UserAchievements::achievementsPage in Opigno statistics 3.x
Build the user achievements page content.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The request object.
\Drupal\user\UserInterface $user: The user to get achievements of.
Return value
array The render array to display the achievements page content.
1 string reference to 'UserAchievements::achievementsPage'
File
- src/
Controller/ UserAchievements.php, line 92
Class
- UserAchievements
- User achievements page controller.
Namespace
Drupal\opigno_statistics\ControllerCode
public function achievementsPage(Request $request, UserInterface $user) : array {
$uid = (int) $user
->id();
$active_tab = $request
->get('tab', 'trainings');
// Build tabs section structure.
$tabs = [];
$names = [
static::TRANINGS_TAB,
static::CERTIFICATES_TAB,
static::BADGES_TAB,
static::SKILLS_TAB,
];
foreach ($names as $name) {
$params = [
'user' => $uid,
'tab' => $name,
];
$url = Url::fromRoute('opigno_statistics.switch_achievement_tabs', $params);
$internal = $url
->getInternalPath();
$url
->setOption('query', [
'token' => $this->csrfToken
->get($internal),
]);
$tabs[$name] = [
'title' => $this
->getTabTitle($name),
'url' => $url
->toString(),
];
}
// Add the sharable post url if socials enabled.
$attached = [];
if ($this->statsManager->isSocialsEnabled) {
$share_url = Url::fromRoute('opigno_social.share_post_content')
->toString();
$attached = [
'library' => [
'opigno_social/post_sharing',
],
'drupalSettings' => [
'opignoSocial' => [
'shareContentUrl' => $share_url instanceof GeneratedUrl ? $share_url
->getGeneratedUrl() : $share_url,
],
],
];
}
return [
'#theme' => 'opigno_user_achievements_page',
'#tabs' => $tabs,
'#active' => $active_tab,
'#content' => $this
->getTabContent($uid, $active_tab),
'#attached' => $attached,
];
}