class UserHooksTest

Contains hook implementations.

Hierarchy

Expanded class hierarchy of UserHooksTest

File

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

Namespace

Drupal\user_hooks_test\Hook
View source
class UserHooksTest {
    public function __construct(StateInterface $state) {
    }
    
    /**
     * Alters the username.
     *
     * @param string|\Drupal\Component\Render\MarkupInterface $name
     *   The username that is displayed for a user.
     * @param \Drupal\Core\Session\AccountInterface $account
     *   The object on which the operation is being performed.
     *
     * @return void
     */
    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>';
            }
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary
UserHooksTest::userFormatNameAlter public function Alters the username.
UserHooksTest::__construct public function

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