Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override order fields #35

Open
caudurieauelma opened this issue Dec 21, 2018 · 0 comments
Open

Override order fields #35

caudurieauelma opened this issue Dec 21, 2018 · 0 comments

Comments

@caudurieauelma
Copy link

caudurieauelma commented Dec 21, 2018

Evolution

We can't override the fields property "propertyOrder" returned by liform.

Suggestion

Currently this is what I use, it works good if you don't fail the fields order set. But my quick solution has multiple default, like more than one field can have the same position, don't have a lot of time to make a correct solution.

<?php

namespace AppBundle\Liform\Transformer;

use Symfony\Component\Form\FormInterface;
use Limenius\Liform\Transformer\CompoundTransformer as BaseCompoundTransformer;

class CompoundTransformer extends BaseCompoundTransformer
{
    /** {@inheritdoc} */
    public function transform(FormInterface $form, array $extensions = [], $widget = null)
    {
        $data = [];
        $order = 1;
        $required = [];

        foreach ($form->all() as $name => $field) {
            // ...
            if ($field->getConfig()->getOption('liform')
                && isset($field->getConfig()->getOption('liform')['propertyOrder'])
            ) {
                $transformedChild['propertyOrder'] = $field->getConfig()->getOption('liform')['propertyOrder'];
            } else {
                $transformedChild['propertyOrder'] = $order;
                $order ++;
            }
            // ...
        }

        // ...
    }
}
@caudurieauelma caudurieauelma changed the title Override fields order Override order fields Dec 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant