UserStatisticsBlock.php in Opigno dashboard 3.x
File
src/Plugin/Block/UserStatisticsBlock.php
View source
<?php
namespace Drupal\opigno_dashboard\Plugin\Block;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\user\UserInterface;
class UserStatisticsBlock extends SiteHeaderBlock implements ContainerFactoryPluginInterface {
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'] ?? [],
];
}
}