You are here

public function UserBlock::build in Content Planner 8

Builds the render array for a dashboard block.

Return value

array The markup for the dashboard block.

Overrides DashboardBlockBase::build

File

src/Plugin/DashboardBlock/UserBlock.php, line 28

Class

UserBlock
Provides a user block for Content Planner Dashboard.

Namespace

Drupal\content_planner\Plugin\DashboardBlock

Code

public function build() {
  $config = $this
    ->getConfiguration();
  $users = $this
    ->getUsers($config);
  if ($users) {
    $user_data = [];
    foreach ($users as $user) {
      $roles = array_map(function ($role) {
        if ($role != 'authenticated') {

          /** @var \Drupal\user\RoleInterface $role_entity */
          $role_entity = $this->entityTypeManager
            ->getStorage('user_role')
            ->load($role);
          return $role_entity ? $role_entity
            ->label() : NULL;
        }
      }, $user
        ->getRoles());
      $user_data[] = [
        'name' => $user
          ->label(),
        'image' => UserProfileImage::generateProfileImageUrl($user, 'content_planner_user_block_profile_image'),
        'roles' => implode(', ', array_filter($roles)),
        'content_count' => $this
          ->getUserContentCount($user
          ->id()),
        'content_kalendertag_count' => $this
          ->getUserContentWorkflowCount($user
          ->id(), 'am_kalendertag_publizieren'),
        'content_draft_count' => $this
          ->getUserContentWorkflowCount($user
          ->id(), 'draft'),
      ];
    }
    return [
      '#theme' => 'content_planner_dashboard_user_block',
      '#users' => $user_data,
    ];
  }
  return [];
}