You are here

function social_user_tokens_alter in Open Social 8

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

Implements hook_tokens_alter().

This is a fallback for when the user object is empty and the display name and URL tokens are not filled in by the other token replacements. In cases like this the account is cancelled, but the message remains behind.

File

modules/social_features/social_user/social_user.module, line 330
The social user module alterations.

Code

function social_user_tokens_alter(&$replacements, $context, $bubbleable_metadata) {

  // Change the display name to that of the Anonymous user when the display name
  // token was not replaced.
  if (isset($context['tokens']['display-name']) && empty($replacements[$context['tokens']['display-name']]) && (array_key_exists('user', $context['data']) && $context['data']['user'] === NULL)) {
    $replacements[$context['tokens']['display-name']] = \Drupal::configFactory()
      ->get('user.settings')
      ->get('anonymous');
  }

  // Empty the URL so it doesn't break rendering when the URL token was not
  // replaced.
  if (isset($context['tokens']['url:absolute']) && empty($replacements[$context['tokens']['url:absolute']]) && (array_key_exists('user', $context['data']) && $context['data']['user'] === NULL)) {
    $replacements[$context['tokens']['url:absolute']] = NULL;
  }
}