You are here

protected function GeneralUserReferenceFormatter::replaceTokensForAnonymous in Formatter Suite 8

Replaces tokens for the anonymous user.

Parameters

string $pattern: The token pattern to operate upon.

Return value

string Returns the token pattern with specific tokens replaced for the anonymous user.

1 call to GeneralUserReferenceFormatter::replaceTokensForAnonymous()
GeneralUserReferenceFormatter::viewElements in src/Plugin/Field/FieldFormatter/GeneralUserReferenceFormatter.php
Builds a renderable array for a field value.

File

src/Plugin/Field/FieldFormatter/GeneralUserReferenceFormatter.php, line 736

Class

GeneralUserReferenceFormatter
Formats a user entity reference as one or more links.

Namespace

Drupal\formatter_suite\Plugin\Field\FieldFormatter

Code

protected function replaceTokensForAnonymous(string $pattern) {
  $pattern = mb_ereg_replace('\\[user:created.*\\]', (string) $this
    ->t('site creation'), $pattern);
  $pattern = mb_ereg_replace('\\[user:last-login.*\\]', (string) $this
    ->t('never'), $pattern);
  $pattern = mb_ereg_replace('\\[user:user_picture.*\\]', '', $pattern);
  $pattern = mb_ereg_replace('\\[user:url.*\\]', '', $pattern);
  return str_replace([
    '[user:uid]',
    '[user:account-name]',
    '[user:display-name]',
    '[user:name]',
    '[user:mail]',
    '[user:edit-url]',
    '[user:cancel-url]',
    '[user:one-time-login-url]',
  ], [
    0,
    'anonymous',
    $this->userSettings
      ->get('anonymous'),
    'anonymous',
    $this
      ->t('None'),
    '',
    '',
    '',
  ], $pattern);
}