Sonataadminbundle: Calling "addChild" without second argument is deprecated since 3.35

Created on 29 May 2018  路  20Comments  路  Source: sonata-project/SonataAdminBundle

I have 2 classes:

In the services.yml

    admin.factura:
        class: AppBundle\Admin\FacturaAdmin
        arguments: [~, AppBundle\Entity\Factura, AppBundle:FacturaAdmin]
        tags:
            - { name: sonata.admin, manager_type: orm, label: Facturas }
        calls:
            - [ addChild, ['@admin.factura_detalle']]
class FacturaDetalleAdmin extends AbstractAdmin {

  protected $baseRouteName = 'factura_detalle';
  protected $baseRoutePattern = 'factura_detalle';
  protected $parentAssociationMapping = 'factura';
.....

class FacturaAdmin extends AbstractAdmin {

  protected $baseRouteName = 'factura';
  protected $baseRoutePattern = 'factura';

If i do de official documentation instructions it not works.
https://sonata-project.org/bundles/admin/3-x/doc/reference/child_admin.html

I need to add " - [ addChild, ['@admin.factura_detalle']]" but this is not compatible wihit symfony 4.0

bug docs

Most helpful comment

@kunicmarko20 we should add an yaml example in the docs, too

All 20 comments

You have to remove


  protected $parentAssociationMapping = 'factura';

and add the name of your child as a second argument here:

        calls:
            - [ addChild, ['@admin.factura_detalle', 'NAME_OF_PARENT']]

I love you!!!!! really tnks!!!!

@kunicmarko20 we should add an yaml example in the docs, too

Yes, that would make it easier for people.

yes, the website documentation doesn't works.

i found this in stack oveflow:

        calls:
            - [ addChild, ['@admin.factura_detalle', 'NAME_OF_CHILD']]

EDIT by OskarStark:

You need to use NAME_OF_PARENT!!!

        calls:
            - [ addChild, ['@admin.factura_detalle', 'NAME_OF_PARENT']]

@jmros can you please make a PR to fix the docs?

I created PR #5115

Is $parentAssociationMapping still necessary now that the parent relationship is defined in the addChild call?

If it's not, maybe it should be removed from the docs too? It's still in VideoAdmin and was confusing for me.

Yes, it should be removed, can you make a PR, please?

Thanks for your Feedback

Sure. simple enough pr. Will do it tmrw or wknd between work

FYI, haven't forgotten this. Just been busy. Will update when I can.

Thank you for coming back 馃憤
In the meantime I fixe this small docs!

Sorry I couldn't help more/sooner. Would love to help more though.

Sorry I couldn't help more/sooner. Would love to help more though.

No problem, every help is appreciated 馃憤

@quazardous works for me.
your association is wrong?

@haivala not the association but something is wrong with my entity. I've tested with a FooBar entity from scratch it's OK, Sorry for the noise. I've delete the post

You have to remove


  protected $parentAssociationMapping = 'factura';

and add the name of your child as a second argument here:

        calls:
            - [ addChild, ['@admin.factura_detalle', 'NAME_OF_PARENT']]

Sorry for the noise, is this possible with SonataAutoConfigureBundle? cause removing $parentAssociationMapping looses parent.

@dotoree you will have to use annotation https://github.com/kunicmarko20/SonataAutoConfigureBundle#adminoptions, there is a children optiom there

@dotoree you will have to use annotation https://github.com/kunicmarko20/SonataAutoConfigureBundle#adminoptions, there is a children optiom there

@kunicmarko20: Already using children annotation, but does not work without $parentAssociationMapping in child admin. Here is my code:

/**
 * @Sonata\AdminOptions(
 *  label="label_authors",
 *  showMosaicButton=false,
 *  group="label_authors",
 *  icon="<i class='fa fa-user-circle-o'></i>",
 *  onTop=true,
 *  children={"App\Admin\AuthorHasPaymentAdmin"}
 * )
 */
final class AuthorAdmin extends AbstractAdmin
{
}

/**
 * @Sonata\AdminOptions(
 *  label="label_author_has_payment",
 *  showInDashboard=false,
 * )
 */
final class AuthorHasPaymentAdmin extends AbstractAdmin
{
    protected $parentAssociationMapping = 'author';
}

The only way I can solve this right now is by removing $parentAssociationMapping and adding preValidate to child admin:

    public function preValidate($payment)
    {
        if ($this->getParent()) {
            $payment->setAuthor($this->getParent()->getSubject());
        }
    }
Was this page helpful?
0 / 5 - 0 ratings