public function UserStatisticsBlock::build in Opigno dashboard 3.x
Builds and returns the renderable array for this block plugin.
If a block should not be rendered because it has no content, then this method must also ensure to return no content: it must then only return an empty array, or an empty array with #cache set (with cacheability metadata indicating the circumstances for it being empty).
Return value
array A renderable array representing the content of the block.
Overrides SiteHeaderBlock::build
See also
\Drupal\block\BlockViewBuilder
File
- src/
Plugin/ Block/ UserStatisticsBlock.php, line 24
Class
- UserStatisticsBlock
- The user statistics block.
Namespace
Drupal\opigno_dashboard\Plugin\BlockCode
public function build() {
if (!$this->user instanceof UserInterface) {
return [
'#cache' => [
'max-age' => 0,
],
];
}
if ($this->user
->isAnonymous()) {
return [
'#cache' => [
'max-age' => -1,
],
];
}
$stats = $this->statsManager
->renderUserStatistics(7);
return [
'#theme' => 'opigno_dashboard_user_statistics_block',
'#user_name' => $this->user
->getDisplayName(),
'#uid' => (int) $this->user
->id(),
'#user_picture' => $this->statsManager
->getUserPicture($this->user, 'user_profile'),
'#role' => $this->statsManager
->getUserRole(),
'#stats' => $stats,
'#attached' => $stats['#attached'] ?? [],
];
}