src/Form/Service/FormService.php
public function resolve(Form $form)
    {
        switch ($form->getType()) {
            case Form::TYPE_FORMIO:
                $components = $form->getSchema();
                $resolverCollection = $this->resolverCollection;
                $resolve = function(&$component) use (&$resolve, $resolverCollection) {
                    switch (true) {
                        case property_exists($component, 'components'):
                            foreach ($component->components as &$subComponent) {
                                $resolve($subComponent);
                            }

                            break;

                        case property_exists($component, 'columns'):
                            foreach ($component->columns as &$column) {
                                foreach ($column->components as &$subComponent) {
                                    $resolve($subComponent);
                                }
                            }

                            break;

                        case property_exists($component, 'defaultValue'):
                            if (null !== $component->defaultValue) {
                                try {
                                    $component->defaultValue = $resolverCollection->resolve($component->defaultValue);
                                } catch (UnresolvedException $exception) {
                                    $component->defaultValue = null;
                                } catch (UnmatchedException $exception) {
                                    // Leave default value as-is
                                }
                            }

                            break;
                    }
                };

                foreach ($components as &$component) {
                    $resolve($component);
                }

                $form->setSchema($components);

                break;

            case Form::TYPE_SYMFONY:
                break;

            default:
                throw new DomainException('Form type does not exist.');
        }

        return $form;
    }
public function resolve(Form $form)
    {
        switch ($form->getType()) {
            case Form::TYPE_FORMIO:
                $components = $form->getSchema();
                $resolverCollection = $this->resolverCollection;
                $resolve = function(&$component) use (&$resolve, $resolverCollection) {
                    switch (true) {
                        case property_exists($component, 'components'):
                            foreach ($component->components as &$subComponent) {
                                $resolve($subComponent);
                            }

                            break;

                        case property_exists($component, 'columns'):
                            foreach ($component->columns as &$column) {
                                foreach ($column->components as &$subComponent) {
                                    $resolve($subComponent);
                                }
                            }

                            break;

                        case property_exists($component, 'defaultValue'):
                            if (null !== $component->defaultValue) {
                                try {
                                    $component->defaultValue = $resolverCollection->resolve($component->defaultValue);
                                } catch (UnresolvedException $exception) {
                                    $component->defaultValue = null;
                                } catch (UnmatchedException $exception) {
                                    // Leave default value as-is
                                }
                            }

                            break;
                    }
                };

                foreach ($components as &$component) {
                    $resolve($component);
                }

                $form->setSchema($components);

                break;

            case Form::TYPE_SYMFONY:
                break;

            default:
                throw new DomainException('Form type does not exist.');
        }

        return $form;
    }
public function resolve ( Form $ form ) { switch ( $ form -> getType ( ) ) { case Form :: TYPE_FORMIO : $ components = $ form -> getSchema ( ) ; $ resolverCollection = $ this -> resolverCollection ; $ resolve = function ( & $ component ) use ( & $ resolve , $ resolverCollection ) { switch ( true ) { case property_exists ( $ component , 'components' ) : foreach ( $ component -> components as & $ subComponent ) { $ resolve ( $ subComponent ) ; } break ; case property_exists ( $ component , 'columns' ) : foreach ( $ component -> columns as & $ column ) { foreach ( $ column -> components as & $ subComponent ) { $ resolve ( $ subComponent ) ; } } break ; case property_exists ( $ component , 'defaultValue' ) : if ( null !== $ component -> defaultValue ) { try { $ component -> defaultValue = $ resolverCollection -> resolve ( $ component -> defaultValue ) ; } catch ( UnresolvedException $ exception ) { $ component -> defaultValue = null ; } catch ( UnmatchedException $ exception ) { // Leave default value as-is } } break ; } } ; foreach ( $ components as & $ component ) { $ resolve ( $ component ) ; } $ form -> setSchema ( $ components ) ; break ; case Form :: TYPE_SYMFONY : break ; default : throw new DomainException ( 'Form type does not exist.' ) ; } return $ form ; }
Resolve a form

@param \Ds\Component\Form\Model\Form $form
@return \Ds\Component\Form\Model\Form
Resolve a form