Skip to content

Commit 1c384d5

Browse files
committed
improve code readability
1 parent 6f40075 commit 1c384d5

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

modules/backend/formwidgets/Repeater.php

+10-17
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,7 @@ protected function processSaveValue($value)
258258
*/
259259
protected function processItems()
260260
{
261-
$currentValue = ($this->loaded === true)
262-
? post($this->formField->getName())
263-
: $this->getLoadValue();
261+
$currentValue = $this->getLoadValue();
264262

265263
// Detect when a child widget is trying to run an AJAX handler
266264
// outside of the form element that contains all the repeater
@@ -344,15 +342,18 @@ protected function makeItemFormWidget($index = 0, $groupCode = null)
344342
return $this->formWidgets[$index] = $widget;
345343
}
346344

345+
public function getLoadValue()
346+
{
347+
return ($this->loaded === true) ? post($this->formField->getName()) : parent::getLoadValue();
348+
}
349+
347350
/**
348351
* Returns the data at a given index.
349352
* @param int $index
350353
*/
351354
protected function getValueFromIndex($index)
352355
{
353-
$value = ($this->loaded === true)
354-
? post($this->formField->getName())
355-
: $this->getLoadValue();
356+
$value = $this->getLoadValue();
356357

357358
if (!is_array($value)) {
358359
$value = [];
@@ -406,18 +407,10 @@ public function onRefresh()
406407
*/
407408
protected function getNextIndex()
408409
{
409-
if ($this->loaded === true) {
410-
$data = post($this->formField->getName());
410+
$data = $this->getLoadValue();
411411

412-
if (is_array($data) && count($data)) {
413-
return (max(array_keys($data)) + 1);
414-
}
415-
} else {
416-
$data = $this->getLoadValue();
417-
418-
if (is_array($data)) {
419-
return count($data);
420-
}
412+
if (is_array($data)) {
413+
return count($data);
421414
}
422415

423416
return 0;

0 commit comments

Comments
 (0)