Jim Panse
Jim Panse

Reputation: 2270

Use sonata_type_collection multiple times in admin

In my sonata admin, i need the same entity collection multiple times, because i filter the collection with criterias

$criteria = Criteria::create()->where(Criteria::expr()->gte('size', 3))->andWhere(Criteria::expr()->eq('type', 'dt'));
    $data = $this->getSubject()->getData()->matching($criteria);

and adding it in configureFormFields by passing it through the data field with

$formMapper->add('data', 'sonata_type_collection', ['data' => $data] ...

That works fine.

But now i want another data from the same collection and display it later to another tab, so i tried

$criteria2 = Criteria::create()->where(Criteria::expr()->gte('size', 4))->andWhere(Criteria::expr()->eq('type', 'du'));
    $data2 = $this->getSubject()->getData()->matching($criteria2);

$formMapper->add('data', 'sonata_type_collection', ['data' => $data2] ...

That doesn't work!

I got no error but it feels like, the last $formmapper->add() call overrides the first one.

Why? How can i spread data filtered from one collection to several tabs?

I must use the sonata_type_collection class because it should be editable inline and shown as list.

Thanks

Upvotes: 1

Views: 364

Answers (1)

OskarStark
OskarStark

Reputation: 404

If I understand you correct, you do not need to persist it, afterwards, right?

You are feeling right, that it overwrites each other. Could you rename the second one to data_foo an make it a non mapped field?

Best, Oskar

Upvotes: 0

Related Questions