Class yii\authclient\widgets\AuthChoice

Inheritanceyii\authclient\widgets\AuthChoice » yii\base\Widget » yii\base\Component » yii\base\Object
Implementsyii\base\Configurable, yii\base\ViewContextInterface
Available since version2.0
Source Code https://github.com/yiisoft/yii2-authclient/blob/master/widgets/AuthChoice.php

AuthChoice prints buttons for authentication via various auth clients.

It opens a popup window for the client authentication process. By default this widget relies on presence of yii\authclient\Collection among application components to get auth clients information.

Example:

<?= yii\authclient\widgets\AuthChoice::widget([
    
'baseAuthUrl' => ['site/auth']
]); 
?>

You can customize the widget appearance by using begin() and end() syntax along with using method clientLink() or createClientUrl(). For example:

<?php
use yii\authclient\widgets\AuthChoice;
?>
<?php $authAuthChoice 
AuthChoice::begin([
    
'baseAuthUrl' => ['site/auth']
]); 
?>
<ul>
<?php foreach ($authAuthChoice->getClients() as $client): ?>
    <li><?php $authAuthChoice->clientLink($client?></li>
<?php endforeach; ?>
</ul>
<?php AuthChoice::end(); ?>

This widget supports following keys for yii\authclient\ClientInterface::getViewOptions() result:

  • popupWidth - integer width of the popup window in pixels.
  • popupHeight - integer height of the popup window in pixels.
  • widget - configuration for the widget, which should be used to render a client link; such widget should be a subclass of yii\authclient\widgets\AuthChoiceItem.

See also yii\authclient\AuthAction.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$autoIdPrefix string The prefix to the automatically generated widget IDs. yii\base\Widget
$autoRender boolean Indicates if widget content, should be rendered automatically. yii\authclient\widgets\AuthChoice
$baseAuthUrl array Base auth URL configuration. yii\authclient\widgets\AuthChoice
$behaviors yii\base\Behavior[] List of behaviors attached to this component yii\base\Component
$clientCollection string Name of the auth client collection application component. yii\authclient\widgets\AuthChoice
$clientIdGetParamName string Name of the GET param , which should be used to passed auth client id to URL defined by $baseAuthUrl. yii\authclient\widgets\AuthChoice
$clients yii\authclient\ClientInterface[] Auth providers yii\authclient\widgets\AuthChoice
$counter integer A counter used to generate $id for widgets. yii\base\Widget
$id string ID of the widget. yii\base\Widget
$options array The HTML attributes that should be rendered in the div HTML tag representing the container element. yii\authclient\widgets\AuthChoice
$popupMode boolean Indicates if popup window should be used instead of direct links. yii\authclient\widgets\AuthChoice
$stack yii\base\Widget[] The widgets that are currently being rendered (not ended). yii\base\Widget
$view yii\web\View The view object that can be used to render views or view files. yii\base\Widget
$viewPath string The directory containing the view files for this widget. yii\base\Widget

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Object
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\Object
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
begin() Begins a widget. yii\base\Widget
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
className() Returns the fully qualified name of this class. yii\base\Object
clientLink() Outputs client auth link. yii\authclient\widgets\AuthChoice
createClientUrl() Composes client auth URL. yii\authclient\widgets\AuthChoice
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
end() Ends a widget. yii\base\Widget
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBaseAuthUrl() yii\authclient\widgets\AuthChoice
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getClients() yii\authclient\widgets\AuthChoice
getId() Returns the ID of the widget. yii\base\Widget
getView() Returns the view object that can be used to render views or view files. yii\base\Widget
getViewPath() Returns the directory containing the view files for this widget. yii\base\Widget
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the widget. yii\authclient\widgets\AuthChoice
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
render() Renders a view. yii\base\Widget
renderFile() Renders a view file. yii\base\Widget
run() Runs the widget. yii\authclient\widgets\AuthChoice
setBaseAuthUrl() yii\authclient\widgets\AuthChoice
setClients() yii\authclient\widgets\AuthChoice
setId() Sets the ID of the widget. yii\base\Widget
setView() Sets the view object to be used by this widget. yii\base\Widget
trigger() Triggers an event. yii\base\Component
widget() Creates a widget instance and runs it. yii\base\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
defaultBaseAuthUrl() Composes default base auth URL configuration. yii\authclient\widgets\AuthChoice
defaultClients() Returns default auth clients list. yii\authclient\widgets\AuthChoice
renderMainContent() Renders the main content, which includes all external services links. yii\authclient\widgets\AuthChoice

Property Details

$autoRender public property

Indicates if widget content, should be rendered automatically. Note: this value automatically set to 'false' at the first call of createClientUrl()

$baseAuthUrl public property
array getBaseAuthUrl( )
void setBaseAuthUrl( array $baseAuthUrl )

Base auth URL configuration.

$clientCollection public property
string $clientCollection 'authClientCollection'

Name of the auth client collection application component. This component will be used to fetch services value if it is not set.

$clientIdGetParamName public property

Name of the GET param , which should be used to passed auth client id to URL defined by $baseAuthUrl.

$clients public property

Auth providers

$options public property
array $options = ['class' => 'auth-clients']

The HTML attributes that should be rendered in the div HTML tag representing the container element.

See also yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

$popupMode public property

Indicates if popup window should be used instead of direct links.

Method Details

clientLink() public method

Outputs client auth link.

void clientLink$client$text null, array $htmlOptions = [] )
$client yii\authclient\ClientInterface

External auth client instance.

$text string

Link text, if not set - default value will be generated.

$htmlOptions array

Link HTML options.

throws yii\base\InvalidConfigException

on wrong configuration.

createClientUrl() public method

Composes client auth URL.

string createClientUrl$provider )
$provider yii\authclient\ClientInterface

External auth client instance.

return string

Auth URL.

defaultBaseAuthUrl() protected method

Composes default base auth URL configuration.

array defaultBaseAuthUrl( )
return array

Base auth URL configuration.

defaultClients() protected method

Returns default auth clients list.

yii\authclient\ClientInterface[] defaultClients( )
return yii\authclient\ClientInterface[]

Auth clients list.

getBaseAuthUrl() public method

array getBaseAuthUrl( )
return array

Base auth URL configuration.

getClients() public method

yii\authclient\ClientInterface[] getClients( )
return yii\authclient\ClientInterface[]

Auth providers

init() public method

Initializes the widget.

void init( )
renderMainContent() protected method

Renders the main content, which includes all external services links.

void renderMainContent( )
run() public method

Runs the widget.

void run( )
setBaseAuthUrl() public method

void setBaseAuthUrl( array $baseAuthUrl )
$baseAuthUrl array

Base auth URL configuration.

setClients() public method

void setClients( array $clients )
$clients yii\authclient\ClientInterface[]

Auth providers