0
votes

I am working on a pre-existing project that uses EasyExtends to extend Sonata's page bundle. The project is based on Symfony 3.3.

There already exists in this project a class in namespace Application\Sonata\PageBundle\Admin called PageAdmin extending BasePageAdmin. It contains definitions two functions -- getPageTypes and configureFormFields.

When I try to clone the function configureTabMenu from the vendor copy of this class -- where it works just fine -- to the Application copy, I get the following complaint from the application:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Application\Sonata\PageBundle\Admin\MenuItemInterface $menu, $action, ?Application\Sonata\PageBundle\Admin\AdminInterface $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

This is frankly a bit more than I easily understand. Is there a simple way to override the existing configureFormFields() method from my vendor folder?

====

Edit #1: Removing the type hinting (which is ill-advised as a long-term strategy but useful for debugging) subs one warning for another. I then get this warning text:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu($menu, $action, $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

====

Edit #2: Changing the method signature to Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL gives me this instead:

Warning: Declaration of Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Application\Sonata\PageBundle\Admin\Knp\Menu\ItemInterface $menu, $action, ?Application\Sonata\PageBundle\Admin\Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) should be compatible with Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL) in . (which is being imported from "/usr/src/app/app/config/routing.yml"). Make sure there is a loader supporting the "sonata_admin" type.

2
Well you are getting that error because the class type hints for the argument are using the wrong classes. I'm not a symfony user, so I don't know if that is something you wrote, or 3rd party code, or what have you.ArtisticPhoenix
Thanks for your comment. I have edited the question slightly after removing the type-hinting.Patrick
subs one warning for another it's the same problem, you can't just remove the type hinting they have to be the same class in the hint as that of the parent, or interface.ArtisticPhoenix

2 Answers

1
votes

Lets make this a bit more readable

Warning: Declaration of

Application\Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Application\Sonata\PageBundle\Admin\MenuItemInterface $menu, $action, ?Application\Sonata\PageBundle\Admin\AdminInterface $childAdmin = NULL)

should be compatible with

Sonata\PageBundle\Admin\PageAdmin::configureTabMenu(Knp\Menu\ItemInterface $menu, $action, ?Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL).

You just have to change it so they are the same type hints.

public function configureTabMenu(Knp\Menu\ItemInterface $menu, $action, Sonata\AdminBundle\Admin\AdminInterface $childAdmin = NULL){


}

That is assuming this is code you wrote, as I said I'm not a Symphony User, but PHP is PHP.

0
votes

It turned out that I was missing two use statements. I copied these from the class I was cloning from:

use Sonata\AdminBundle\Admin\AdminInterface;
use Knp\Menu\ItemInterface as MenuItemInterface;

... and everything worked.