From 1c384d5eabfdd0486a4155a1515257eec7da685f Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sat, 15 Mar 2025 13:41:20 -0400 Subject: [PATCH 1/3] improve code readability --- modules/backend/formwidgets/Repeater.php | 27 +++++++++--------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index 4e834c8c3f..feb19f10ec 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -258,9 +258,7 @@ protected function processSaveValue($value) */ protected function processItems() { - $currentValue = ($this->loaded === true) - ? post($this->formField->getName()) - : $this->getLoadValue(); + $currentValue = $this->getLoadValue(); // Detect when a child widget is trying to run an AJAX handler // outside of the form element that contains all the repeater @@ -344,15 +342,18 @@ protected function makeItemFormWidget($index = 0, $groupCode = null) return $this->formWidgets[$index] = $widget; } + public function getLoadValue() + { + return ($this->loaded === true) ? post($this->formField->getName()) : parent::getLoadValue(); + } + /** * Returns the data at a given index. * @param int $index */ protected function getValueFromIndex($index) { - $value = ($this->loaded === true) - ? post($this->formField->getName()) - : $this->getLoadValue(); + $value = $this->getLoadValue(); if (!is_array($value)) { $value = []; @@ -406,18 +407,10 @@ public function onRefresh() */ protected function getNextIndex() { - if ($this->loaded === true) { - $data = post($this->formField->getName()); + $data = $this->getLoadValue(); - if (is_array($data) && count($data)) { - return (max(array_keys($data)) + 1); - } - } else { - $data = $this->getLoadValue(); - - if (is_array($data)) { - return count($data); - } + if (is_array($data)) { + return count($data); } return 0; From f31a7eca6b20cb6ec42f75bd4936dd8059e955e2 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Tue, 18 Mar 2025 10:35:21 -0400 Subject: [PATCH 2/3] Revert "improve code readability" This reverts commit 1c384d5eabfdd0486a4155a1515257eec7da685f. --- modules/backend/formwidgets/Repeater.php | 27 +++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/backend/formwidgets/Repeater.php b/modules/backend/formwidgets/Repeater.php index feb19f10ec..4e834c8c3f 100644 --- a/modules/backend/formwidgets/Repeater.php +++ b/modules/backend/formwidgets/Repeater.php @@ -258,7 +258,9 @@ protected function processSaveValue($value) */ protected function processItems() { - $currentValue = $this->getLoadValue(); + $currentValue = ($this->loaded === true) + ? post($this->formField->getName()) + : $this->getLoadValue(); // Detect when a child widget is trying to run an AJAX handler // outside of the form element that contains all the repeater @@ -342,18 +344,15 @@ protected function makeItemFormWidget($index = 0, $groupCode = null) return $this->formWidgets[$index] = $widget; } - public function getLoadValue() - { - return ($this->loaded === true) ? post($this->formField->getName()) : parent::getLoadValue(); - } - /** * Returns the data at a given index. * @param int $index */ protected function getValueFromIndex($index) { - $value = $this->getLoadValue(); + $value = ($this->loaded === true) + ? post($this->formField->getName()) + : $this->getLoadValue(); if (!is_array($value)) { $value = []; @@ -407,10 +406,18 @@ public function onRefresh() */ protected function getNextIndex() { - $data = $this->getLoadValue(); + if ($this->loaded === true) { + $data = post($this->formField->getName()); - if (is_array($data)) { - return count($data); + if (is_array($data) && count($data)) { + return (max(array_keys($data)) + 1); + } + } else { + $data = $this->getLoadValue(); + + if (is_array($data)) { + return count($data); + } } return 0; From f3374285b3377250374458fd4c9c8441f742feaf Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Tue, 18 Mar 2025 10:47:12 -0400 Subject: [PATCH 3/3] fetch sensitive value from model --- modules/backend/formwidgets/Sensitive.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/backend/formwidgets/Sensitive.php b/modules/backend/formwidgets/Sensitive.php index 8ab91b87f9..3f9ebc74e7 100644 --- a/modules/backend/formwidgets/Sensitive.php +++ b/modules/backend/formwidgets/Sensitive.php @@ -1,6 +1,7 @@ formField->value !== null && $this->formField->value != $this->hiddenPlaceholder) { + return $this->formField->value; + } + + $parts = HtmlHelper::nameToArray($this->getFieldName()); + array_shift($parts); // remove Model name + $fieldName = array_shift($parts); + + $value = $this->model->getAttribute($fieldName); + + if (count($parts) && is_array($value)) { + $value = array_get($value, implode('.', $parts)); + } + + return $value; + } + /** * @inheritDoc */