From 883e4935bb3e2b974263512813c203fddbd681ac Mon Sep 17 00:00:00 2001 From: "Marco (Valandur)" Date: Fri, 21 Dec 2018 16:18:20 +0100 Subject: [PATCH] fix(treeview): Fix setting value after constructor call not working --- src/TreeView.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/TreeView.php b/src/TreeView.php index cfd12c7..71998c0 100644 --- a/src/TreeView.php +++ b/src/TreeView.php @@ -53,13 +53,20 @@ public function __construct($name, $title = null, $section = null) $this->section = $section; $this->context = singleton(PageElement::class)->getDefaultSearchContext(); - // Open default elements - $this->opens = new \stdClass(); - foreach ($this->getItems() as $item) { - $this->openRecursive($item); + if ($section) { + // Open default elements + $this->opens = new \stdClass(); + foreach ($this->getItems() as $item) { + $this->openRecursive($item); + } } } + public function setValue($value, $data = null) { + $this->section = $value; + return $this; + } + /** * Saves this TreeView into the specified record * @@ -874,3 +881,5 @@ private function closeItem($path) unset($opens->{$path[count($path) - 1]}); } } + +class TreeView_Readonly extends TreeView {}