| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* @copyright © Melograno Venture Studio. All rights reserved. |
| 5 |
* @licence See LICENCE.md for license details. |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace IvyForms\Services\Shortcode; |
| 9 |
|
| 10 |
use IvyForms\Common\Exceptions\ValidationException; |
| 11 |
use IvyForms\Factory\Field\FieldFactory; |
| 12 |
|
| 13 |
/** |
| 14 |
* Collects field entities from shortcode form payloads, skipping invalid fields. |
| 15 |
*/ |
| 16 |
class ShortcodeFieldCollector |
| 17 |
{ |
| 18 |
/** |
| 19 |
* @param array<string, array<string, mixed>> $formList |
| 20 |
* |
| 21 |
* @return array<object> |
| 22 |
*/ |
| 23 |
public static function collect(array $formList): array |
| 24 |
{ |
| 25 |
$allFields = []; |
| 26 |
|
| 27 |
foreach ($formList as $formData) { |
| 28 |
foreach ($formData['fields'] as $fieldData) { |
| 29 |
try { |
| 30 |
$allFields[] = FieldFactory::create($fieldData); |
| 31 |
} catch (ValidationException $e) { |
| 32 |
continue; |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
return $allFields; |
| 38 |
} |
| 39 |
} |
| 40 |
|