Skip to content

Commit

Permalink
Call prefixRecordFields() after getRecordFieldsUpdateCallback() to al…
Browse files Browse the repository at this point in the history
…low the callback to work with unprefixed field names
  • Loading branch information
Zauberfisch committed May 19, 2020
1 parent 895bd3d commit 2e0f816
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/Form/ArrayListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -309,7 +309,7 @@ public function handleSubField($fullFieldName) {
public function saveInto(\DataObjectInterface $record) {
$record->{$this->name} = $this->Value();
}

private static $allowed_actions = [
'addRecord',
];
Expand Down Expand Up @@ -355,7 +355,7 @@ public function setCompactLayout($bool) {
public function isCompactLayout() {
return $this->compactLayout;
}

/**
* @param bool $bool
* @return ArrayListField
Expand All @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -439,7 +439,7 @@ public function fieldLabels() {
$arr = array_merge($arr, $this->fieldLabels);
return $arr;
}

public function fieldLabel($name) {
return $this->fieldLabels()[$name];
}
Expand Down

0 comments on commit 2e0f816

Please sign in to comment.