concrete/src/Form/Service/Widget/UserSelector.php
public function selectUser($fieldName, $uID = false)
    {
        $v = View::getRequestInstance();
        $v->requireAsset('core/users');

        $request = $this->app->make(Request::class);
        if ($request->request->has($fieldName)) {
            $selectedUID = $request->request->get($fieldName);
        } elseif ($request->query->has($fieldName)) {
            $selectedUID = $request->query->get($fieldName);
        } else {
            $selectedUID = $uID;
        }
        if ($selectedUID && $this->app->make(Numbers::class)->integer($selectedUID, 1)) {
            $userInfo = $this->app->make(UserInfoRepository::class)->getByID((int) $selectedUID);
        } else {
            $userInfo = null;
        }
        $selectedUID = $userInfo ? $userInfo->getUserID() : null;

        $permissions = new Checker();
        if ($permissions->canAccessUserSearch()) {
            $identifier = $this->app->make(Identifier::class)->getString(32);
            $args = ['inputName' => $fieldName];
            if ($userInfo) {
                $args['uID'] = $userInfo->getUserID();
            }
            $args = json_encode($args);
            $html = <<<EOL
<div data-user-selector="{$identifier}"></div>
<script>
$(function() {
    $('[data-user-selector={$identifier}]').concreteUserSelector({$args});
});
</script>
EOL;
        } else {
            // Read only
            $uAvatar = null;
            if ($userInfo) {
                $uName = $userInfo->getUserDisplayName();
                $a = $userInfo->getUserAvatar();
                if ($a) {
                    $uAvatar = $a->getPath();
                }
            } else {
                $uName = t('(None Selected)');
            }
            if (!$uAvatar) {
                $uAvatar = $this->app->make('config')->get('concrete.icons.user_avatar.default');
            }

            $html = <<<EOL
<div class="ccm-item-selector">
    <div class="ccm-item-selector-item-selected">
        <input type="hidden" name="{$fieldName}" value="{$selectedUID}">
        <div class="ccm-item-selector-item-selected-thumbnail">
            <img src="{$uAvatar}" alt="admin" class="u-avatar">
        </div>
        <div class="ccm-item-selector-item-selected-title">{$uName}</div>
    </div>
</div>
EOL;
        }

        return $html;
    }
public function selectUser($fieldName, $uID = false)
    {
        $v = View::getRequestInstance();
        $v->requireAsset('core/users');

        $request = $this->app->make(Request::class);
        if ($request->request->has($fieldName)) {
            $selectedUID = $request->request->get($fieldName);
        } elseif ($request->query->has($fieldName)) {
            $selectedUID = $request->query->get($fieldName);
        } else {
            $selectedUID = $uID;
        }
        if ($selectedUID && $this->app->make(Numbers::class)->integer($selectedUID, 1)) {
            $userInfo = $this->app->make(UserInfoRepository::class)->getByID((int) $selectedUID);
        } else {
            $userInfo = null;
        }
        $selectedUID = $userInfo ? $userInfo->getUserID() : null;

        $permissions = new Checker();
        if ($permissions->canAccessUserSearch()) {
            $identifier = $this->app->make(Identifier::class)->getString(32);
            $args = ['inputName' => $fieldName];
            if ($userInfo) {
                $args['uID'] = $userInfo->getUserID();
            }
            $args = json_encode($args);
            $html = <<<EOL
<div data-user-selector="{$identifier}"></div>
<script>
$(function() {
    $('[data-user-selector={$identifier}]').concreteUserSelector({$args});
});
</script>
EOL;
        } else {
            // Read only
            $uAvatar = null;
            if ($userInfo) {
                $uName = $userInfo->getUserDisplayName();
                $a = $userInfo->getUserAvatar();
                if ($a) {
                    $uAvatar = $a->getPath();
                }
            } else {
                $uName = t('(None Selected)');
            }
            if (!$uAvatar) {
                $uAvatar = $this->app->make('config')->get('concrete.icons.user_avatar.default');
            }

            $html = <<<EOL
<div class="ccm-item-selector">
    <div class="ccm-item-selector-item-selected">
        <input type="hidden" name="{$fieldName}" value="{$selectedUID}">
        <div class="ccm-item-selector-item-selected-thumbnail">
            <img src="{$uAvatar}" alt="admin" class="u-avatar">
        </div>
        <div class="ccm-item-selector-item-selected-title">{$uName}</div>
    </div>
</div>
EOL;
        }

        return $html;
    }
public function selectUser ( $ fieldName , $ uID = false ) { $ v = View :: getRequestInstance ( ) ; $ v -> requireAsset ( 'core/users' ) ; $ request = $ this -> app -> make ( Request :: class ) ; if ( $ request -> request -> has ( $ fieldName ) ) { $ selectedUID = $ request -> request -> get ( $ fieldName ) ; } elseif ( $ request -> query -> has ( $ fieldName ) ) { $ selectedUID = $ request -> query -> get ( $ fieldName ) ; } else { $ selectedUID = $ uID ; } if ( $ selectedUID && $ this -> app -> make ( Numbers :: class ) -> integer ( $ selectedUID , 1 ) ) { $ userInfo = $ this -> app -> make ( UserInfoRepository :: class ) -> getByID ( ( int ) $ selectedUID ) ; } else { $ userInfo = null ; } $ selectedUID = $ userInfo ? $ userInfo -> getUserID ( ) : null ; $ permissions = new Checker ( ) ; if ( $ permissions -> canAccessUserSearch ( ) ) { $ identifier = $ this -> app -> make ( Identifier :: class ) -> getString ( 32 ) ; $ args = [ 'inputName' => $ fieldName ] ; if ( $ userInfo ) { $ args [ 'uID' ] = $ userInfo -> getUserID ( ) ; } $ args = json_encode ( $ args ) ; $ html =  <<<EOL
<div data-user-selector="{$identifier}"></div>
<script>
$(function() {
    $('[data-user-selector={$identifier}]').concreteUserSelector({$args});
});
</script>
EOL ; } else { // Read only $ uAvatar = null ; if ( $ userInfo ) { $ uName = $ userInfo -> getUserDisplayName ( ) ; $ a = $ userInfo -> getUserAvatar ( ) ; if ( $ a ) { $ uAvatar = $ a -> getPath ( ) ; } } else { $ uName = t ( '(None Selected)' ) ; } if ( ! $ uAvatar ) { $ uAvatar = $ this -> app -> make ( 'config' ) -> get ( 'concrete.icons.user_avatar.default' ) ; } $ html =  <<<EOL
<div class="ccm-item-selector">
    <div class="ccm-item-selector-item-selected">
        <input type="hidden" name="{$fieldName}" value="{$selectedUID}">
        <div class="ccm-item-selector-item-selected-thumbnail">
            <img src="{$uAvatar}" alt="admin" class="u-avatar">
        </div>
        <div class="ccm-item-selector-item-selected-title">{$uName}</div>
    </div>
</div>
EOL ; } return $ html ; }
Build the HTML to be placed in a page to choose a user using a popup dialog.

@param string $fieldName the name of the field
@param int|false $uID the ID of the user to be initially selected

@return string

@example
<code>
$userSelector->selectUser('userID', USER_SUPER_ID); // prints out the admin user and makes it changeable.
</code>.
Build the HTML to be placed in a page to choose a user using a popup dialog .