You are here

function _social_profile_get_contact_url in Open Social 8.3

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  2. 8 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  3. 8.2 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  4. 8.4 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  5. 8.5 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  6. 8.6 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  7. 8.7 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  8. 8.8 modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  9. 10.3.x modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  10. 10.0.x modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  11. 10.1.x modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()
  12. 10.2.x modules/social_features/social_profile/social_profile.module \_social_profile_get_contact_url()

Get the contact URL. This can be private message or other means of contact.

Parameters

\Drupal\user\Entity\User $account: The user object.

Return value

\Drupal\Core\Url The URL to contact the user.

1 call to _social_profile_get_contact_url()
social_profile_preprocess_profile in modules/social_features/social_profile/social_profile.module
Prepares variables for profile templates.

File

modules/social_features/social_profile/social_profile.module, line 386
The Social profile module.

Code

function _social_profile_get_contact_url(User $account) {
  if (\Drupal::moduleHandler()
    ->moduleExists('social_private_message')) {
    $current_user = \Drupal::currentUser();
    if ($current_user
      ->hasPermission('use private messaging system') && $current_user
      ->id() != $account
      ->id()) {
      $members = [
        $current_user,
        $account,
      ];
      $thread_id = \Drupal::service('private_message.mapper')
        ->getThreadIdForMembers($members);
      if ($thread_id) {
        return Url::fromRoute('entity.private_message_thread.canonical', [
          'private_message_thread' => $thread_id,
        ], [
          'attributes' => [
            'class' => [
              'private_message_link',
            ],
          ],
        ]);
      }
      else {
        return Url::fromRoute('private_message.private_message_create', [], [
          'query' => [
            'recipient' => $account
              ->id(),
          ],
        ]);
      }
    }
  }
  return Url::fromUserInput('/user/' . $account
    ->id() . '/information');
}