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.
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.