fix TypeError: Cannot access offset of type string on string caused by legacy options attribute

This commit is contained in:
ralf 2024-07-16 17:35:07 +02:00
parent 485d6a7f40
commit 4248a85665

View File

@ -205,9 +205,9 @@ class Tree extends Etemplate\Widget
{
return (boolean)array_filter($cats, function($cat) use($id)
{
return $cat['value'] == $id || (
return is_array($cat) && ($cat['value'] == $id || (
!empty($cat['children']) && is_array($cat['children']) && static::in_cats($id, $cat['children'])
);
));
});
}
@ -235,7 +235,11 @@ class Tree extends Etemplate\Widget
// we can not validate if autoloading is enabled
if (!$this->attrs['autoloading'])
{
$allowed = $this->attrs['multiple'] ? array() : array('' => $this->attrs['options']);
$options = empty($this->attrs['options']) ? [] : explode(',', $this->attrs['options']);
$allowed = $this->attrs['multiple'] || empty($options[0]) || is_numeric($options[0]) ? [] : [[
'id' => '',
'label' => $options[0],
]];
$allowed += self::selOptions($form_name);
foreach((array) $value as $val)
{