From 4248a8566515324273933cded938020c567746b4 Mon Sep 17 00:00:00 2001 From: ralf Date: Tue, 16 Jul 2024 17:35:07 +0200 Subject: [PATCH] fix TypeError: Cannot access offset of type string on string caused by legacy options attribute --- api/src/Etemplate/Widget/Tree.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/api/src/Etemplate/Widget/Tree.php b/api/src/Etemplate/Widget/Tree.php index 801b0cca13..82ecf54ac3 100644 --- a/api/src/Etemplate/Widget/Tree.php +++ b/api/src/Etemplate/Widget/Tree.php @@ -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) {