Class yii\authclient\widgets\AuthChoice

Inheritanceyii\authclient\widgets\AuthChoice » yii\base\Widget
Available since version2.0

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 \yii\authclient\widgets\begin() and \yii\authclient\widgets\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><?= $authAuthChoice->clientLink($client) ?></li>
<?php endforeach; ?>
</ul>
<?php AuthChoice::end(); ?>

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

  • popupWidth: int, width of the popup window in pixels.
  • popupHeight: int, height of the popup window in pixels.
  • widget: array, 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
$autoRender boolean Indicates if widget content, should be rendered automatically. yii\authclient\widgets\AuthChoice
$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 \yii\authclient\widgets\baseAuthUrl. yii\authclient\widgets\AuthChoice
$clientOptions array Additional options to be passed to the underlying JS plugin. yii\authclient\widgets\AuthChoice
$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

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()

public boolean $autoRender true
$clientCollection public property

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

public string $clientCollection 'authClientCollection'
$clientIdGetParamName public property

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

public string $clientIdGetParamName 'authclient'
$clientOptions public property

Additional options to be passed to the underlying JS plugin.

public array $clientOptions = []
$options public property

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.

public array $options = []
$popupMode public property

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

public boolean $popupMode true

Method Details

clientLink() public method

Outputs client auth link.

public string 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.

return string

Generated HTML.

throws \yii\base\InvalidConfigException

on wrong configuration.

createClientUrl() public method

Composes client auth URL.

public string createClientUrl ( $client )
$client yii\authclient\ClientInterface

External auth client instance.

return string

Auth URL.

defaultBaseAuthUrl() protected method

Composes default base auth URL configuration.

protected array defaultBaseAuthUrl ( )
return array

Base auth URL configuration.

defaultClients() protected method

Returns default auth clients list.

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

Auth clients list.

getBaseAuthUrl() public method

public array getBaseAuthUrl ( )
return array

Base auth URL configuration.

getClients() public method

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

Auth providers

init() public method

Initializes the widget.

public void init ( )
renderMainContent() protected method

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

protected string renderMainContent ( )
return string

Generated HTML.

run() public method

Runs the widget.

public string run ( )
return string

Rendered HTML.

setBaseAuthUrl() public method

public void setBaseAuthUrl ( array $baseAuthUrl )
$baseAuthUrl array

Base auth URL configuration.

setClients() public method

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

Auth providers