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

Add support for Symfony Form inherit_data #34

Merged
merged 5 commits into from
Sep 20, 2024

Conversation

Bartheyrman22
Copy link
Contributor

No description provided.

@gilles-g
Copy link
Contributor

gilles-g commented Sep 2, 2024

Hi @Bartheyrman22

Could you show me what you want to do with inherit_data please?

@Bartheyrman22
Copy link
Contributor Author

Bartheyrman22 commented Sep 2, 2024

Hi @gilles-g,

I want to reuse my ResultFilterType that I use seperately in a filter-form.
In a combined filter-form I want to add the ResultFilterType as the base table/filter and add the other filtertypes as joined tables/filters. (OrderFilterType and SampleFilterType).

Basically I found that we need to drop the result-alias when inherit_data is set. This because it is not used by the form builder itself also.

See the folllowing code snippet.

public function buildForm(FormBuilderInterface $builder, array $options): void
    {
        $builder
            ->add('order', OrderFilterType::class, [
                'add_shared' => function (FilterBuilderExecuterInterface $qbe) {
                    $closure = function (QueryBuilder $filterBuilder, $alias, $joinAlias, Expr $expr) {
                        $filterBuilder->leftJoin(OrderTable::class, $joinAlias, Join::WITH, $alias . '.orderId = ' . $joinAlias . '.orderId');
                    };

                    $qbe->addOnce($qbe->getAlias().'.order', 'o', $closure);
                }
            ])
            ->add('sample', SampleFilterType::class, [
                'add_shared' => function (FilterBuilderExecuterInterface $qbe) {
                    $closure = function (QueryBuilder $filterBuilder, $alias, $joinAlias, Expr $expr) {
                        $filterBuilder->leftJoin(SampleTable::class, $joinAlias, Join::WITH, $alias . '.sampleId = ' . $joinAlias . '.sampleId');
                    };

                    $qbe->addOnce($qbe->getAlias().'.sample', 's', $closure);
                }
            ])
            ->add('result', ResultFilterType::class, [
                'inherit_data' => true
            ])
        ;
    }
``

@gilles-g
Copy link
Contributor

gilles-g commented Sep 2, 2024

Ok thanks, Do you think you could add a test?

@Bartheyrman22
Copy link
Contributor Author

Added an extra test while other tests are still working.

@Bartheyrman22
Copy link
Contributor Author

Bartheyrman22 commented Sep 19, 2024

Hi @gilles-g,
Any feedback so far? Lookiing forward to see the support in a main release. 😉

@gilles-g
Copy link
Contributor

Hi @Bartheyrman22

sorry for the delay, I will merge and create tags

@gilles-g gilles-g merged commit 7aaaf5c into SpiriitLabs:master Sep 20, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants