yii2: #16681 cause error if the $config param not already include 'options' key
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
- Fixes #17220: Fixed widgets with no options — committed to yiisoft/yii2 by samdark 5 years ago
- Revert "Fixes #17220: Fixed widgets with no options" This reverts commit a7f98964151d5894d9862fb0a1bf80040de86b69. — committed to yiisoft/yii2 by samdark 5 years ago
- Fixed error if the $config param not already include 'options' key (#17220) — committed to s1lver/yii2 by s1lver 5 years ago
- Fixes #17220: Fixed error when using non-InputWidget in active form field — committed to yiisoft/yii2 by s1lver 5 years ago
If widget should behave as
InputWidget, then it should extendInputWidget. Havingoptionsproperty 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
optionsproperty manually, sinceInputWidgetalready has it. And if your widget does not extendInputWidget,inputOptionswill 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, ])
`