Example #1
0
 /**
  * Initializes the widget
  *
  * @throws InvalidConfigException
  */
 public function init()
 {
     $this->_msgCat = 'kveditable';
     parent::init();
     if (empty($this->inputType)) {
         throw new InvalidConfigException("The 'type' of editable input must be set.");
     }
     if (!Config::isValidInput($this->inputType)) {
         throw new InvalidConfigException("Invalid input type '{$this->inputType}'.");
     }
     if ($this->inputType === self::INPUT_WIDGET && empty($this->widgetClass)) {
         throw new InvalidConfigException("The 'widgetClass' must be set when the 'inputType' is set to 'widget'.");
     }
     if (Config::isDropdownInput($this->inputType) && !isset($this->data)) {
         throw new InvalidConfigException("You must set the 'data' property for '{$this->inputType}'.");
     }
     if (!empty($this->formClass) && !class_exists($this->formClass)) {
         throw new InvalidConfigException("The form class '{$this->formClass}' does not exist.");
     }
     Config::validateInputWidget($this->inputType);
     $this->initI18N(__DIR__);
     $this->initOptions();
     $this->_popoverOptions['options']['id'] = $this->options['id'] . '-popover';
     $this->_popoverOptions['toggleButton']['id'] = $this->options['id'] . '-targ';
     $this->registerAssets();
     echo Html::beginTag('div', $this->containerOptions);
     if ($this->format == self::FORMAT_BUTTON) {
         echo Html::tag('div', $this->displayValue, $this->editableValueOptions);
     }
     if ($this->asPopover === true) {
         PopoverX::begin($this->_popoverOptions);
     } elseif ($this->format !== self::FORMAT_BUTTON) {
         echo $this->renderToggleButton();
     }
     echo Html::beginTag('div', $this->contentOptions);
     $class = $this->formClass;
     $this->_form = $class::begin($this->formOptions);
     if (!$this->_form instanceof \yii\widgets\ActiveForm) {
         throw new InvalidConfigException("The form class '{$class}' MUST extend from \\yii\\widgets\\ActiveForm.");
     }
 }