Use Doctrine in RequiredCustomFieldValidator

[MAILPOET-3032]
This commit is contained in:
Jan Lysý
2021-03-30 17:36:53 +02:00
committed by Veljko V
parent 5ceb084c64
commit 69d5eb42f7
3 changed files with 91 additions and 47 deletions

View File

@ -194,4 +194,37 @@ class FormEntity {
public function getSettingsSegmentIds(): array {
return $this->settings['segments'] ?? [];
}
public function getFields(array $body = null): array {
$body = $body ?? $this->getBody();
if (empty($body)) {
return [];
}
$skippedTypes = ['html', 'divider', 'submit'];
$nestedTypes = ['column', 'columns'];
$fields = [];
foreach ($body as $field) {
if (!empty($field['type']) && in_array($field['type'], $nestedTypes) && !empty($field['body'])) {
$nestedFields = $this->getFields($field['body']);
if ($nestedFields) {
$fields = array_merge($fields, $nestedFields);
}
continue;
}
if (empty($field['id']) || empty($field['type']) || in_array($field['type'], $skippedTypes)) {
continue;
}
if ((int)$field['id'] > 0) {
$fields[] = 'cf_' . $field['id'];
} else {
$fields[] = $field['id'];
}
}
return $fields;
}
}