yii2: #16681 cause error if the $config param not already include 'options' key

#16681

    public function widget($class, $config = [])
    {
        foreach ($this->inputOptions as $key => $value) {
            if (!isset($config['options'][$key])) {
                $config['options'][$key] = $value;
            }
        }

must be

    public function widget($class, $config = [])
    {
        foreach ($this->inputOptions as $key => $value) {
             if(!isset($config['options']){
                  $config['options'] = [];
              }
            if (!isset($config['options'][$key])) {
                $config['options'][$key] = $value;
            }
        }

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (20 by maintainers)

Commits related to this issue

Most upvoted comments

That would require any widget to InputWidget, my suggestion would be to check if the class has a ‘options’ property.

If widget should behave as InputWidget, then it should extend InputWidget. Having options property in widget does not mean that it should be input options. Your PR may break BC by assuming intentions by property name.

@s1lver Sorry, I don’t get your point. I’m proposing to move this:

https://github.com/yiisoft/yii2/blob/f7fcc0043e1263a281172c8e28c688e2c6e83839/framework/widgets/ActiveField.php#L766-L770

Under this condition:

https://github.com/yiisoft/yii2/blob/f7fcc0043e1263a281172c8e28c688e2c6e83839/framework/widgets/ActiveField.php#L775

You don’t need add options property manually, since InputWidget already has it. And if your widget does not extend InputWidget, inputOptions will be ignored like before.

i have this code and i get error on it

` $form->field($model, “xs”)->widget(PhotoInput::className(), [ ‘form’ => $form, ‘imgWidth’ => 200, ‘imgHeight’ =>400, ])

`