public function FriendInteractBlock::build in Heartbeat 8
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
Overrides BlockPluginInterface::build
File
- src/
Plugin/ Block/ FriendInteractBlock.php, line 33
Class
- FriendInteractBlock
- Provides a 'FriendInteractBlock' block.
Namespace
Drupal\heartbeat\Plugin\BlockCode
public function build() {
$uid = \Drupal::config('heartbeat_friend_interact.settings')
->get('uid');
$user = $this->entityTypeManager
->getStorage('user')
->load($uid);
$userPic = $user
->get('user_picture')
->getValue();
if (!empty($userPic) && ($profilePic = $user
->get('user_picture')
->getValue()[0]['target_id'])) {
$pic = File::load($profilePic);
if ($pic !== NULL) {
$style = $this->entityTypeManager
->getStorage('image_style')
->load('thumbnail');
$rendered = $style
->buildUrl($pic
->getFileUri());
}
}
$flagMarkup = Heartbeat::flagAjaxBuilder('friendship', $user, \Drupal::service('flag'));
return [
'#theme' => 'friend_interaction',
'#user' => 'This user',
'#flag' => $flagMarkup,
'#userPic' => $rendered,
'#cache' => array(
'max-age' => 0,
),
];
}