Update form::getFields to return also nested fields
[MAILPOET-2609]
This commit is contained in:
committed by
Pavel Dohnal
parent
0c64c38e61
commit
7bf1b69a94
@ -43,22 +43,33 @@ class Form extends Model {
|
|||||||
return parent::save();
|
return parent::save();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getFieldList() {
|
public function getFieldList(array $body = null) {
|
||||||
$body = $this->getBody();
|
$body = $body ?? $this->getBody();
|
||||||
if (empty($body)) {
|
if (empty($body)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$skippedTypes = ['html', 'divider', 'submit'];
|
$skippedTypes = ['html', 'divider', 'submit'];
|
||||||
|
$nestedTypes = ['column', 'columns'];
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
|
||||||
foreach ((array)$body as $field) {
|
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'])
|
if (empty($field['id'])
|
||||||
|| empty($field['type'])
|
|| empty($field['type'])
|
||||||
|| in_array($field['type'], $skippedTypes)
|
|| in_array($field['type'], $skippedTypes)
|
||||||
) {
|
) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($field['id'] > 0) {
|
if ($field['id'] > 0) {
|
||||||
$fields[] = 'cf_' . $field['id'];
|
$fields[] = 'cf_' . $field['id'];
|
||||||
} else {
|
} else {
|
||||||
|
@ -105,13 +105,27 @@ class FormTest extends \MailPoetTest {
|
|||||||
'type' => 'text',
|
'type' => 'text',
|
||||||
'id' => 2,
|
'id' => 2,
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'type' => 'columns',
|
||||||
|
'body' => [
|
||||||
|
[
|
||||||
|
'type' => 'column',
|
||||||
|
'body' => [
|
||||||
|
[
|
||||||
|
'type' => 'text',
|
||||||
|
'id' => 3,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'type' => 'submit',
|
'type' => 'submit',
|
||||||
'id' => 'submit',
|
'id' => 'submit',
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
expect($form->getFieldList())->equals(['email', 'cf_2']);
|
expect($form->getFieldList())->equals(['email', 'cf_2', 'cf_3']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItUpdatesSuccessMessagesWhenConfirmationIsDisabled() {
|
public function testItUpdatesSuccessMessagesWhenConfirmationIsDisabled() {
|
||||||
|
Reference in New Issue
Block a user