yii\authclient\widgets\AuthChoice::clientLink PHP Method

    public function clientLink($client, $text = null, array $htmlOptions = [])
    {
        $viewOptions = $client->getViewOptions();
        if (empty($viewOptions['widget'])) {
            if ($text === null) {
                $text = Html::tag('span', '', ['class' => 'auth-icon ' . $client->getName()]);
            }
            if (!isset($htmlOptions['class'])) {
                $htmlOptions['class'] = $client->getName();
            }
            if (!isset($htmlOptions['title'])) {
                $htmlOptions['title'] = $client->getTitle();
            }
            Html::addCssClass($htmlOptions, ['widget' => 'auth-link']);
            if ($this->popupMode) {
                if (isset($viewOptions['popupWidth'])) {
                    $htmlOptions['data-popup-width'] = $viewOptions['popupWidth'];
                }
                if (isset($viewOptions['popupHeight'])) {
                    $htmlOptions['data-popup-height'] = $viewOptions['popupHeight'];
                }
            }
            return Html::a($text, $this->createClientUrl($client), $htmlOptions);
        }
        $widgetConfig = $viewOptions['widget'];
        if (!isset($widgetConfig['class'])) {
            throw new InvalidConfigException('Widget config "class" parameter is missing');
        }
        /* @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;
        return $widgetClass::widget($widgetConfig);
    }

Usage Example

Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function clientLink($client, $text = null, array $htmlOptions = array())
 {
     $viewOptions = $client->getViewOptions();
     if (isset($viewOptions['widget'])) {
         parent::clientLink($client, $text, $htmlOptions);
         return;
     }
     if (isset($viewOptions['buttonBackgroundColor'])) {
         $textColor = isset($viewOptions['buttonColor']) ? $viewOptions['buttonColor'] : '#FFF';
         $btnStyle = Html::cssStyleFromArray(['color' => $textColor . '!important', 'background-color' => $viewOptions['buttonBackgroundColor'] . '!important']);
         $btnClasses = '.btn-ac-' . $client->getName() . ', .btn-ac-' . $client->getName() . ':hover, .btn-ac-' . $client->getName() . ':active, .btn-ac-' . $client->getName() . ':visited';
         if ($this->showButtonColors) {
             echo Html::style($btnClasses . ' {' . $btnStyle . '}');
         }
     }
     if (!isset($htmlOptions['class'])) {
         $htmlOption['class'] = '';
     }
     $htmlOptions['class'] .= ' ' . 'btn btn-default btn-ac-' . $client->getName();
     $icon = isset($viewOptions['cssIcon']) ? '<i class="' . $viewOptions['cssIcon'] . '" aria-hidden="true"></i>' : '';
     echo parent::clientLink($client, $icon . $client->getTitle(), $htmlOptions);
     return;
     parent::clientLink($client, $text, $htmlOptions);
 }