Skip to content

Instantly share code, notes, and snippets.

@mattcdavis1
Created May 13, 2021 20:48
Show Gist options
  • Save mattcdavis1/afccee40ccbe240d6590b68fa098a20f to your computer and use it in GitHub Desktop.
Save mattcdavis1/afccee40ccbe240d6590b68fa098a20f to your computer and use it in GitHub Desktop.
<?php
namespace datacode\app\services\formie;
use ReflectionClass;
class Helper
{
public static function getFormField($formieField)
{
$fields = [];
$className = (new ReflectionClass($formieField))->getShortName();
if (in_array($className, ['FlexField', 'Section'])) {
return $fields;
}
if (in_array($className, ['Group'])) {
$groupFields = $formieField->getFields();
foreach ($groupFields as $groupField) {
$groupFieldClassName = (new ReflectionClass($groupField))->getShortName();
if (in_array($groupFieldClassName, ['Group'])) {
return self::getFormField($groupFieldClassName);
} else {
$fields[] = $groupField;
}
}
} else {
$fields[] = $formieField;
}
return $fields;
}
public static function getFormFields($formieForm)
{
$formieFields = $formieForm->getFields();
$fields = [];
foreach ($formieFields as $formieField) {
foreach (self::getFormField($formieField) as $field) {
$fields[] = $field;
}
}
return $fields;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment