You are here

public function SocialInviteLocalActionsBlock::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/SocialInviteLocalActionsBlock.php \Drupal\social_group_invite\Plugin\Block\SocialInviteLocalActionsBlock::build()
  2. 10.0.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialInviteLocalActionsBlock.php \Drupal\social_group_invite\Plugin\Block\SocialInviteLocalActionsBlock::build()
  3. 10.1.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialInviteLocalActionsBlock.php \Drupal\social_group_invite\Plugin\Block\SocialInviteLocalActionsBlock::build()
  4. 10.2.x modules/social_features/social_group/modules/social_group_invite/src/Plugin/Block/SocialInviteLocalActionsBlock.php \Drupal\social_group_invite\Plugin\Block\SocialInviteLocalActionsBlock::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/SocialInviteLocalActionsBlock.php, line 124

Class

SocialInviteLocalActionsBlock
Provides a 'SocialInviteLocalActionsBlock' block.

Namespace

Drupal\social_group_invite\Plugin\Block

Code

public function build() {
  $build = [];

  // Get current group so we can build correct links.
  if (_social_group_invite_current_type_enabled_invites()) {
    $group = _social_group_get_current_group();
    $links = [
      '#type' => 'dropbutton',
      '#attributes' => [
        'class' => [
          'add-users-dropbutton',
        ],
        'no-split' => [
          'title' => $this
            ->t('Add members'),
          'alignment' => 'right',
        ],
      ],
      '#links' => [
        'add_directly' => [
          'title' => $this
            ->t('Add directly'),
          'url' => Url::fromRoute('entity.group_content.add_form', [
            'plugin_id' => 'group_membership',
            'group' => $group
              ->id(),
          ]),
        ],
        'invite_by_mail' => [
          'title' => $this
            ->t('Invite users'),
          'url' => Url::fromRoute('ginvite.invitation.bulk', [
            'group' => $group
              ->id(),
          ]),
        ],
        'view_invites' => [
          'title' => $this
            ->t('View invites'),
          'url' => Url::fromRoute('view.social_group_invitations.page_1', [
            'group' => $group
              ->id(),
          ]),
        ],
      ],
    ];
    $build['content'] = $links;
  }
  return $build;
}