public function MemberCountBlock::build in Organic groups 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/ MemberCountBlock.php, line 120
Class
- MemberCountBlock
- Provides a block that shows the number of members in the current group.
Namespace
Drupal\og\Plugin\BlockCode
public function build() {
// Do not render anything if there is no group in the current context.
$group = $this->ogContext
->getGroup();
if (empty($group)) {
return [];
}
$states = [
OgMembershipInterface::STATE_ACTIVE,
];
if ($this->configuration['count_blocked_users']) {
$states[] = OgMembershipInterface::STATE_BLOCKED;
}
if ($this->configuration['count_pending_users']) {
$states[] = OgMembershipInterface::STATE_PENDING;
}
$membership_ids = $this->membershipManager
->getGroupMembershipIdsByRoleNames($group, [
OgRoleInterface::AUTHENTICATED,
], $states);
return [
'#theme' => 'og_member_count',
'#count' => count($membership_ids),
'#group' => $group,
'#group_label' => $group
->label(),
'#membership_states' => $states,
];
}