You are here

public static function UserProfileImage::generateProfileImageUrl in Content Planner 8

Helper method that generate image url of the user.

Parameters

\Drupal\user\UserInterface $user: User entity.

string $image_style: Image style ID.

Return value

bool|string Image url or FALSE on failure.

3 calls to UserProfileImage::generateProfileImageUrl()
BaseEntry::getUserPictureFromCache in src/Component/BaseEntry.php
Drupal static method to retrieve the user picture url by user id.
RecentKanbanActivities::buildKanbanLogActivities in modules/content_kanban/src/Plugin/DashboardBlock/RecentKanbanActivities.php
Builds the log entries.
UserBlock::build in src/Plugin/DashboardBlock/UserBlock.php
Builds the render array for a dashboard block.

File

src/UserProfileImage.php, line 25

Class

UserProfileImage
Class UserProfileImage.

Namespace

Drupal\content_planner

Code

public static function generateProfileImageUrl(UserInterface $user, $image_style) {
  if (($user_picture_field = $user
    ->get('user_picture')
    ->getValue()) && ($image_file_id = $user_picture_field[0]['target_id']) && ($file_entity = File::load($image_file_id)) && ($style = ImageStyle::load($image_style))) {

    // Build image style url.
    return $style
      ->buildUrl($file_entity
      ->getFileUri());
  }
  return FALSE;
}