From 2e0f8163bbb1f87cf65c2ee550a4a1045aef88d5 Mon Sep 17 00:00:00 2001 From: Zauberfisch Date: Tue, 19 May 2020 05:08:03 +0200 Subject: [PATCH] Call prefixRecordFields() after getRecordFieldsUpdateCallback() to allow the callback to work with unprefixed field names --- src/Form/ArrayListField.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Form/ArrayListField.php b/src/Form/ArrayListField.php index 7b4d11c..b69014a 100644 --- a/src/Form/ArrayListField.php +++ b/src/Form/ArrayListField.php @@ -17,7 +17,7 @@ class ArrayListField extends FormField { protected $compactLayout = false; protected $emptyDefaultValue = false; protected $fieldLabels = []; - + public function __construct($name, $title, $recordClassNames) { $recordClassNames = is_array($recordClassNames) ? array_values($recordClassNames) : [$recordClassNames]; foreach ($recordClassNames as $className) { @@ -182,11 +182,11 @@ protected function getRecordFields($index, AbstractDataObject $record) { ->setName('ArrayListFieldControls') ->addExtraClass('controls') ); - $this->prefixRecordFields($index, $recordFields, $className); $callback = $this->getRecordFieldsUpdateCallback(); if ($callback) { $recordFields = call_user_func($callback, $recordFields, $this, $record, $index); } + $this->prefixRecordFields($index, $recordFields, $className); return (new CompositeField($recordFields))->addExtraClass('record'); } @@ -281,7 +281,7 @@ protected function prefixRecordFields($index, $fields, $className) { } } } - + public function getPrefixedRecordFieldName($index, $fieldName, $className) { $classNameHash = array_search($className, $this->recordClassNames); return sprintf('%s[%s][%s][%s]', $this->getName(), $index, $classNameHash, $fieldName); @@ -309,7 +309,7 @@ public function handleSubField($fullFieldName) { public function saveInto(\DataObjectInterface $record) { $record->{$this->name} = $this->Value(); } - + private static $allowed_actions = [ 'addRecord', ]; @@ -355,7 +355,7 @@ public function setCompactLayout($bool) { public function isCompactLayout() { return $this->compactLayout; } - + /** * @param bool $bool * @return ArrayListField @@ -364,14 +364,14 @@ public function setEmptyDefaultValue($bool) { $this->emptyDefaultValue = $bool; return $this; } - + /** * @return bool */ public function hasEmptyDefaultValue() { return $this->emptyDefaultValue; } - + public function setForm($form) { parent::setForm($form); } @@ -422,11 +422,11 @@ public function setRecordFieldsUpdateCallback($recordFieldsUpdateCallback) { public function getRecordFieldsUpdateCallback() { return $this->recordFieldsUpdateCallback; } - + public function setFieldLabel($name, $string) { $this->fieldLabels[$name] = $string; } - + public function fieldLabels() { $arr = []; foreach ($this->recordClassNames as $class) { @@ -439,7 +439,7 @@ public function fieldLabels() { $arr = array_merge($arr, $this->fieldLabels); return $arr; } - + public function fieldLabel($name) { return $this->fieldLabels()[$name]; }