function UserHooksTest::userFormatNameAlter

Alters the username.

Parameters

string|\Drupal\Component\Render\MarkupInterface $name: The username that is displayed for a user.

\Drupal\Core\Session\AccountInterface $account: The object on which the operation is being performed.

Return value

void

File

core/modules/user/tests/modules/user_hooks_test/src/Hook/UserHooksTest.php, line 30

Class

UserHooksTest
Contains hook implementations.

Namespace

Drupal\user_hooks_test\Hook

Code

public function userFormatNameAlter(&$name, AccountInterface $account) {
    if ($this->state
        ->get('user_hooks_test_user_format_name_alter', FALSE)) {
        if ($this->state
            ->get('user_hooks_test_user_format_name_alter_safe', FALSE)) {
            $name = new FormattableMarkup('<em>@uid</em>', [
                '@uid' => $account->id(),
            ]);
        }
        else {
            $name = '<em>' . $account->id() . '</em>';
        }
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.