sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

Calling "addChild" without second argument is deprecated since 3.35 #5109

Closed jmros closed 6 years ago

jmros commented 6 years ago

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

kunicmarko20 commented 6 years ago

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']]
jmros commented 6 years ago

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

OskarStark commented 6 years ago

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

kunicmarko20 commented 6 years ago

Yes, that would make it easier for people.

jmros commented 6 years ago

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']]
greg0ire commented 6 years ago

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

OskarStark commented 6 years ago

I created PR #5115

johnpancoast commented 6 years ago

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.

kunicmarko20 commented 6 years ago

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

OskarStark commented 6 years ago

Thanks for your Feedback

johnpancoast commented 6 years ago

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

johnpancoast commented 6 years ago

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

OskarStark commented 6 years ago

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

johnpancoast commented 6 years ago

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

OskarStark commented 6 years ago

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

No problem, every help is appreciated 👍

haivala commented 5 years ago

@quazardous works for me. your association is wrong?

quazardous commented 5 years ago

@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

dotoree commented 5 years ago

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.

kunicmarko20 commented 5 years ago

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

dotoree commented 5 years ago

@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());
        }
    }
fafiebig commented 2 years ago

hello, i know i am very late to the party. have an issue with this feature as before i could add unidirectional references with the addChild method (do not have the parent field). so how can this be done now? only the cross table knows the connection between parent and children. but i dont want an extra admin for the crosstable as you might want with sortable references.