Skip to content

Commit

Permalink
yii\authclient\AuthChoiceItem extracted
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Mar 17, 2015
1 parent b199a71 commit 4c26906
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
6 changes: 6 additions & 0 deletions extensions/authclient/widgets/AuthChoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
* This widget supports following keys for [[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 [[AuthChoiceItem]].
*
* @see \yii\authclient\AuthAction
*
Expand Down Expand Up @@ -201,8 +203,12 @@ public function clientLink($client, $text = null, array $htmlOptions = [])
}
/* @var $widgetClass Widget */
$widgetClass = $widgetConfig['class'];
if (!(is_subclass_of($widgetClass, AuthChoiceItem::className()))) {
throw new InvalidConfigException('Item widget class must be subclass of "' . AuthChoiceItem::className() . '"');
}
unset($widgetConfig['class']);
$widgetConfig['client'] = $client;
$widgetConfig['authChoice'] = $this;
echo $widgetClass::widget($widgetConfig);
}
}
Expand Down
31 changes: 31 additions & 0 deletions extensions/authclient/widgets/AuthChoiceItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yii\authclient\widgets;

use yii\base\Widget;

/**
* AuthChoiceItem is a base class for creating widgets, which can be used to render link
* for auth client at [[AuthChoice]].
*
* @see AuthChoice
*
* @author Paul Klimov <[email protected]>
* @since 2.0
*/
class AuthChoiceItem extends Widget
{
/**
* @var \yii\authclient\ClientInterface auth client instance.
*/
public $client;
/**
* @var AuthChoice parent AuthChoice widget
*/
public $authChoice;
}
13 changes: 5 additions & 8 deletions extensions/authclient/widgets/GooglePlusButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use yii\authclient\clients\GooglePlus;
use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\web\View;
Expand All @@ -21,17 +20,14 @@
* @see GooglePlus
* @see https://developers.google.com/+/web/signin/
*
* @property \yii\authclient\clients\GooglePlus $client auth client instance.
* @property string|array $callback
*
* @author Paul Klimov <[email protected]>
* @since 2.0
*/
class GooglePlusButton extends Widget
class GooglePlusButton extends AuthChoiceItem
{
/**
* @var GooglePlus google auth client instance.
*/
public $client;
/**
* @var array button tag HTML options, which will be merged with the default ones.
*/
Expand Down Expand Up @@ -94,9 +90,10 @@ public function run()
protected function generateCallback($url = [])
{
if (empty($url)) {
$url = ['auth', 'authclient' => $this->client->id];
$url = $this->authChoice->createClientUrl($this->client);
} else {
$url = Url::to($url);
}
$url = Url::to($url);
if (strpos($url, '?') === false) {
$url .= '?';
} else {
Expand Down

0 comments on commit 4c26906

Please sign in to comment.