You are here

public function ProfileStatisticBlock::build in Open Social 10.2.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php \Drupal\social_profile\Plugin\Block\ProfileStatisticBlock::build()
  2. 8.8 modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php \Drupal\social_profile\Plugin\Block\ProfileStatisticBlock::build()
  3. 10.3.x modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php \Drupal\social_profile\Plugin\Block\ProfileStatisticBlock::build()
  4. 10.0.x modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php \Drupal\social_profile\Plugin\Block\ProfileStatisticBlock::build()
  5. 10.1.x modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php \Drupal\social_profile\Plugin\Block\ProfileStatisticBlock::build()

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 BlockPluginInterface::build

See also

\Drupal\block\BlockViewBuilder

File

modules/social_features/social_profile/src/Plugin/Block/ProfileStatisticBlock.php, line 65

Class

ProfileStatisticBlock
Provides a 'ProfileStatisticBlock' block.

Namespace

Drupal\social_profile\Plugin\Block

Code

public function build() {
  $build = [];
  $account = $this
    ->getContextValue('user');
  $storage = $this->entityTypeManager
    ->getStorage('profile');
  $profile = $storage
    ->loadByUser($account, 'profile');
  if ($profile) {
    $build = $this->entityTypeManager
      ->getViewBuilder('profile')
      ->view($profile, 'statistic');
  }
  return $build;
}