You are here

function social_core_social_user_account_header_account_links in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_core/social_core.module \social_core_social_user_account_header_account_links()
  2. 10.0.x modules/social_features/social_core/social_core.module \social_core_social_user_account_header_account_links()
  3. 10.1.x modules/social_features/social_core/social_core.module \social_core_social_user_account_header_account_links()
  4. 10.2.x modules/social_features/social_core/social_core.module \social_core_social_user_account_header_account_links()

Implements hook_social_user_account_header_account_links().

Adds the "My invitations" link to the user menu.

File

modules/social_features/social_core/social_core.module, line 131
The Social core module.

Code

function social_core_social_user_account_header_account_links(array $context) {

  // We require a user for this link.
  if (empty($context['user']) || !$context['user'] instanceof AccountInterface) {
    return [];
  }

  /** @var \Drupal\social_core\InviteService $core_invites */
  $core_invites = \Drupal::service('social_core.invite');

  // Only when there are actual Invite plugins enabled.
  if (!empty($core_invites
    ->getInviteData('name'))) {
    $title = new TranslatableMarkup('Invites');

    // If we have invites show the number.
    if (!empty($core_invites
      ->getInviteData('amount'))) {
      $title = [
        '#type' => 'inline_template',
        '#template' => '<span>{% trans %}Invites{% endtrans %}</span> <span{{ attributes }}>{{ icon }}</span>',
        '#context' => [
          'attributes' => new Attribute([
            'class' => 'margin-left-xs badge badge-accent badge--pill',
          ]),
          'icon' => (string) $core_invites
            ->getInviteData('amount'),
        ],
      ];
    }
    return [
      'divider_no_mobile' => [
        '#wrapper_attributes' => [
          'class' => [
            'divider',
            'hidden-for-phone-only',
          ],
          'role' => 'separator',
        ],
        '#weight' => 325,
      ],
      'my_invites' => [
        '#type' => 'link',
        '#attributes' => [
          'title' => new TranslatableMarkup('Invites'),
        ],
        '#title' => $title,
        '#weight' => 350,
      ] + Url::fromRoute('social_core.my_invites')
        ->toRenderArray(),
    ];
  }
}