How to override widget in yii2?

There is a widget in the extension yii2-authclient here it is specifically that widget
I need to redo the method for displaying buttons this public function clientLink
I created another widget with this method so
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
*/

namespace frontend\widget;

use yii\base\InvalidConfigException;
use yii\base\Widget;
use yii\helpers\Html;
use yii\authclient\ClientInterface;
use yii\authclient\widgets\AuthChoice;
use yii\authclient\widgets\AuthChoiceItem;


class MyAuthChoice extends AuthChoice
{

/**
 * Outputs client auth link.
 * @param ClientInterface $client client instance external auth.
 * @param string $text link text, if not set - default value will be generated.
 * @param array $htmlOptions HTML options link.
 * @return string generated HTML.
 * @throws InvalidConfigException on wrong configuration.
*/
 public function clientLink($client, $text = null, array $htmlOptions = [])
{
 $viewOptions = $client->getViewOptions();

 if (empty($viewOptions['widget'])) {
 if ($text === null) {
 $text = Html::tag('span', ", ['class' => 'blabla' . $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::AuthChoice))) {
 throw new InvalidConfigException('Item widget class must be subclass of "' . AuthChoiceItem::AuthChoice . '"');
}
unset($widgetConfig['class']);
 $widgetConfig['client'] = $client;
 $widgetConfig['authChoice'] = $this;
 return $widgetClass::widget($widgetConfig);
}


}


Feet now widget does not work, why? although if you vardump the widget AuthChoice and MyAuthChoice show the same object
What is not so?
April 4th 20 at 13:19
1 answer
April 4th 20 at 13:21
Solution
You write that changed? Everyone should compare your code with the original?

As for me, this part of the code is not correct:
$widgetClass = $widgetConfig['class'];
 if (!(is_subclass_of($widgetClass, AuthChoiceItem::AuthChoice))) {
 throw new InvalidConfigException('Item widget class must be subclass of "' . AuthChoiceItem::AuthChoice . '"');
 }


Must be
AuthChoiceItem::class
AuthChoiceItem::className() so, too, does not work, I have not only changed here
$text = Html::tag('span', ", ['class' => 'blabla' . $client->getName()]);

class' => 'blabla changed to the test - lauretta.Hirthe78 commented on April 4th 20 at 13:24
@lauretta.Hirthe78,
I have not changed

I created another widget with this method so

In my opinion this is mutually exclusive

Feet now widget does not work, why?

And what does this mean? There are errors? - anne commented on April 4th 20 at 13:27

Find more questions by tags Yii