kartik\social\Widget::init PHP Method

init() public method

Initialize the widget
public init ( )
    public function init()
    {
        parent::init();
        if ($this->validPlugins !== false && empty($this->type)) {
            throw new InvalidConfigException("The plugin 'type' must be set.");
        }
        if ($this->validPlugins !== false && !in_array($this->type, $this->validPlugins)) {
            throw new InvalidConfigException("Invalid plugin type 'type'.");
        }
        Yii::setAlias('@kvsocial', dirname(__FILE__));
        if (empty($this->i18n)) {
            $this->i18n = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@kvsocial/messages', 'forceTranslation' => true];
        }
        Yii::$app->i18n->translations['kvsocial'] = $this->i18n;
        if ($this->noscript !== false && empty($this->noscript)) {
            $this->noscript = Yii::t('kvsocial', 'You must enable Javascript on your browser for the site to work optimally and display sections completely.');
        }
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Initialize the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     static $initDone = false;
     $this->validPlugins = [self::COMMENTS, self::POST, self::COMMUNITY, self::LIKE, self::RECO, self::POLL, self::AUTH, self::SHARE, self::SUBSCRIBE];
     parent::init();
     $this->setConfig('vk');
     $initRequired = !in_array($this->type, [self::POST, self::COMMUNITY, self::SHARE, self::SUBSCRIBE]);
     $this->_initVk = $initRequired && !$initDone;
     if ($this->_initVk) {
         $initDone = true;
     }
     if (empty($this->options['id'])) {
         $this->options['id'] = $this->getId();
     }
     if (empty($this->type)) {
         throw new InvalidConfigException("The plugin 'type' must be set.");
     }
     if (empty($this->apiId) && $this->_initVk) {
         throw new InvalidConfigException("The VKontakte 'apiId' has not been set.");
     }
     if (!isset($this->noscript)) {
         $this->noscript = Yii::t('kvsocial', 'Please enable JavaScript on your browser to view the VKontakte {pluginName} plugin correctly on this site.', ['pluginName' => Yii::t('kvsocial', str_replace('vk_', '', $this->type))]);
     }
     $this->_options = $this->options;
     $this->options = ['id' => $this->options['id'], 'class' => $this->type];
     unset($this->_options['id']);
     $this->registerAssets();
     echo $this->renderPlugin();
 }
All Usage Examples Of kartik\social\Widget::init