Update form::getFields to return also nested fields

[MAILPOET-2609]
This commit is contained in:
Rostislav Wolny
2020-02-19 15:44:36 +01:00
committed by Pavel Dohnal
parent 0c64c38e61
commit 7bf1b69a94
2 changed files with 28 additions and 3 deletions

View File

@ -43,22 +43,33 @@ class Form extends Model {
return parent::save();
}
public function getFieldList() {
$body = $this->getBody();
public function getFieldList(array $body = null) {
$body = $body ?? $this->getBody();
if (empty($body)) {
return false;
}
$skippedTypes = ['html', 'divider', 'submit'];
$nestedTypes = ['column', 'columns'];
$fields = [];
foreach ((array)$body as $field) {
if (!empty($field['type'])
&& in_array($field['type'], $nestedTypes)
&& !empty($field['body'])
) {
$nestedFields = $this->getFieldList($field['body']);
$fields = array_merge($fields, $nestedFields);
continue;
}
if (empty($field['id'])
|| empty($field['type'])
|| in_array($field['type'], $skippedTypes)
) {
continue;
}
if ($field['id'] > 0) {
$fields[] = 'cf_' . $field['id'];
} else {