You are here

public function SocialGroupInviteNotificationBlock::build in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialGroupInviteNotificationBlock.php \Drupal\social_group_invite\Plugin\Block\SocialGroupInviteNotificationBlock::build()
  2. 10.0.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialGroupInviteNotificationBlock.php \Drupal\social_group_invite\Plugin\Block\SocialGroupInviteNotificationBlock::build()
  3. 10.1.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialGroupInviteNotificationBlock.php \Drupal\social_group_invite\Plugin\Block\SocialGroupInviteNotificationBlock::build()
  4. 10.2.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialGroupInviteNotificationBlock.php \Drupal\social_group_invite\Plugin\Block\SocialGroupInviteNotificationBlock::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_group/modules/social_group_invite/src/Plugin/Block/SocialGroupInviteNotificationBlock.php, line 101

Class

SocialGroupInviteNotificationBlock
Provides a 'Invite notification' block.

Namespace

Drupal\social_group_invite\Plugin\Block

Code

public function build() {

  // Only when group invite is installed.
  if (!$this->group
    ->getGroupType()
    ->hasContentPlugin('group_invitation')) {
    return [];
  }

  // Check if the user (entity_id) has a pending invite for the group.
  $properties = [
    'entity_id' => $this->account
      ->id(),
    'gid' => $this->group
      ->id(),
    'invitation_status' => GroupInvitation::INVITATION_PENDING,
  ];

  // No pending invites for the current.
  if (empty($this->inviteLoader
    ->loadByProperties($properties))) {
    return [];
  }
  return [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $this
      ->t('You have been invited to join this group'),
    '#attributes' => [
      'class' => [
        'alert',
        'alert-warning',
      ],
    ],
  ];
}