You are here

public function PCPBlock::build in Profile Complete Percent 8

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

src/Plugin/Block/PCPBlock.php, line 82

Class

PCPBlock
Provides a 'PCP' block.

Namespace

Drupal\pcp\Plugin\Block

Code

public function build() {
  $user_id = $this->accountProxy
    ->id();

  /** @var \Drupal\user\UserInterface $user */
  $user = User::load($user_id);
  $pcp_data = $this->pcpService
    ->getCompletePercentageData($user);
  if ($pcp_data['hide_pcp_block'] && $pcp_data['incomplete'] == 0 || $pcp_data['total'] == 0) {
    return [];
  }
  $pcp_markup = [
    '#theme' => 'pcp_template',
    '#uid' => $pcp_data['uid'],
    '#total' => $pcp_data['total'],
    '#open_link' => $pcp_data['open_link'],
    '#completed' => $pcp_data['completed'],
    '#incomplete' => $pcp_data['incomplete'],
    '#next_percent' => $pcp_data['next_percent'],
    '#nextfield_name' => $pcp_data['nextfield_name'],
    '#nextfield_title' => $pcp_data['nextfield_title'],
    '#current_percent' => $pcp_data['current_percent'],
    '#attached' => [
      'library' => [
        'pcp/pcp.block',
      ],
    ],
  ];
  return $pcp_markup;
}