I would like to use the AlterPHP extension as well as the Wandi extension with EasyAdminBundle.
But we face some issue configuration both of them at the same time.
We used to have this config file when using only AlterPhp :
#routes/easy_admin.yaml
easy_admin_bundle:
resource: '@EasyAdminExtensionBundle/Controller/EasyAdminController.php'
prefix: /admin
type: annotation
And it was fine when we only used this bundle. However, now we want to use this bundle as well as the one quoted previously but it also needs to replace the easyadmin controller by the one from the new bundle.
So both extension wants to do the same thing and both extend the BaseAdminController from EasyAdmin.
What would be the best way to use both in the same project ?
I found a solution by making a custom controller that extends the AdminController from Wandi and copying the methods from the AdminController from Alterphp inside the custom controller. However, it seems like an odd solution to this problem.
I decided to contact both AlterPHP and Wandi on github and send a pull request on their extensions to use trait in their controller to make it easier to use multiple extensions.
So both of them answered to me :
Wandi reviewed my PR and merged it to master. It is now available in release 2.0.2.
AlterPHP reviewed my PR and merged it to master. It is now available in release 3.0.1
So with those changes it is way easier to use both extensions (and similar EasyAdminExtension) by using those new traits :
use Wandi\EasyAdminPlusBundle\Controller\AdminController as WandiController;
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use Wandi\EasyAdminPlusBundle\Controller\AdminControllerTrait as WandiTrait;
use AlterPHP\EasyAdminExtensionBundle\Controller\AdminExtensionControllerTrait as AlterPHPTrait;
class CustomAdminController extends EasyAdminController
{
use AlterPHPTrait, WandiTrait;
//You may have to solve conflict between those traits
}
You may have multiple problems such as services not known by the controller or methods defined multiple time.
I just had to redefine getSubscribedServices in my controller to add those used by AlterPHP and Wandi, as well as resolving a conflict with the method isActionAllowed defined in both traits.
use AlterPHP\EasyAdminExtensionBundle\Security\AdminAuthorizationChecker;
use EasyCorp\Bundle\EasyAdminBundle\Controller\EasyAdminController;
use Wandi\EasyAdminPlusBundle\Controller\AdminControllerTrait as WandiTrait;
use AlterPHP\EasyAdminExtensionBundle\Controller\AdminExtensionControllerTrait as AlterPHPTrait;
use Wandi\EasyAdminPlusBundle\Exporter\Configuration\NormalizerConfigPass;
use Wandi\EasyAdminPlusBundle\Exporter\Configuration\PropertyConfigPass;
use Wandi\EasyAdminPlusBundle\Exporter\Configuration\TemplateConfigPass;
class CustomAdminController extends EasyAdminController
{
use AlterPHPTrait,WandiTrait { AlterPHPTrait::isActionAllowed insteadof WandiTrait; }
//It is important to set the subscribed services from the trait because they cannot use them otherwise.
public static function getSubscribedServices(): array
{
return \array_merge(parent::getSubscribedServices(), [
AdminAuthorizationChecker::class, //This one is for AlterPHP and those below for Wandi
'wandi.easy_admin_plus.exporter.configuration.normalizer_config_pass' => NormalizerConfigPass::class,
'wandi.easy_admin_plus.exporter.configuration.property_config_pass' => PropertyConfigPass::class,
'wandi.easy_admin_plus.exporter.configuration.template_config_pass' => TemplateConfigPass::class,
]);
}
}
I had to modify my services.yaml to be able to redefine getSubscribedServices for Wandi.
#services.yaml
services:
#...
Wandi\EasyAdminPlusBundle\Exporter\Configuration\NormalizerConfigPass: '@wandi.easy_admin_plus.exporter.configuration.normalizer_config_pass'
Wandi\EasyAdminPlusBundle\Exporter\Configuration\PropertyConfigPass: '@wandi.easy_admin_plus.exporter.configuration.property_config_pass'
Wandi\EasyAdminPlusBundle\Exporter\Configuration\TemplateConfigPass: '@wandi.easy_admin_plus.exporter.configuration.template_config_pass'