From 077d40e4d4ec5f2ccff7205cfa11f55d01d92500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 24 Jul 2021 12:59:04 +0200 Subject: [PATCH] collect running callback triggers directly from render tree --- src/Callback.php | 2 -- src/View.php | 26 ++++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Callback.php b/src/Callback.php index bfb7a327a8..ed29b5d498 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -49,8 +49,6 @@ protected function init(): void public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; - - $this->getOwner()->stickyGet(self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger); } public function getUrlTrigger(): string diff --git a/src/View.php b/src/View.php index 174036890f..86a6b8080a 100644 --- a/src/View.php +++ b/src/View.php @@ -599,7 +599,7 @@ public function removeAttr($property) */ public function jsUrl($page = []) { - return $this->getApp()->jsUrl($page, false, $this->_getStickyArgs()); + return $this->getApp()->jsUrl($page, false, array_merge($this->getRunningCallbackArgs(false, $page), $this->_getStickyArgs())); } /** @@ -613,7 +613,29 @@ public function jsUrl($page = []) */ public function url($page = []) { - return $this->getApp()->url($page, false, $this->_getStickyArgs()); + return $this->getApp()->url($page, false, array_merge($this->getRunningCallbackArgs(false, $page), $this->_getStickyArgs())); + } + + protected function getRunningCallbackArgs(bool $isTerminated, $page): array + { + $args = []; + foreach ($this->elements as $v) { + if ($v instanceof Callback && $v->isTriggered() && $v->canTrigger()) { + if (($page[Callback::URL_QUERY_TARGET] ?? null) === $v->getUrlTrigger()) { + $isTerminated = true; + } + + if ($isTerminated) { + $args[Callback::URL_QUERY_TRIGGER_PREFIX . $v->getUrlTrigger()] = $v->getTriggeredValue(); + } + } + } + + if ($this->issetOwner() && $this->getOwner() instanceof self) { + $args = array_merge($this->getOwner()->getRunningCallbackArgs($isTerminated, $page), $args); + } + + return $args; } /**