-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disabling some exporters #214
Comments
IMO, it's not possible by config |
Thanks!, CompilerPass it is, then. |
Hi, Could you explain how you did it please ? I'm trying to disable the .json format of the orders export. Thanks ! |
I registered a compiler pass that only added the exporter I wanted to the admin (order export in xlsx format). I looked into the base exporter pass for reference. You also need to set <?php
namespace App\DependencyInjection\Compiler;
use FriendsOfSylius\SyliusImportExportPlugin\Exporter\ExporterRegistry;
use FriendsOfSylius\SyliusImportExportPlugin\Listener\ExportButtonGridListener;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* This CompilerPass adds the export button only in the Order's admin list
* It is needed because FriendsOfSylius\SyliusImportExportPlugin RegisterExporterPass adds
* the export button on all registered resources (customer, products...)
*/
final class RegisterOrderExportButtonPass implements CompilerPassInterface
{
private const EXPORTER_TYPE = 'sylius.order';
private const EXPORTER_FORMAT = 'xlsx';
private const EXPORTER_ID = 'sylius.exporter.orders.xlsx';
private const CONTROLLER_NAME = 'sylius.controller.export_data_order';
private const EVENT_NAME = 'sylius.grid.admin_order';
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container): void
{
if ($container->has(self::EXPORTER_ID) == false) {
return;
}
$type = self::EXPORTER_TYPE;
$formats = [self::EXPORTER_FORMAT];
$eventHookName = ExporterRegistry::buildGridButtonsEventHookName($type, $formats) . '_export';
if ($container->has($eventHookName)) {
return;
}
if (!$container->has(self::CONTROLLER_NAME)) {
return;
}
$container
->register(
$eventHookName,
ExportButtonGridListener::class
)
->setAutowired(false)
->addArgument($type)
->addArgument($formats)
->addMethodCall('setRequest', [new Reference('request_stack')])
->addTag(
'kernel.event_listener',
[
'event' => self::EVENT_NAME,
'method' => 'onSyliusGridAdmin',
]
);
}
private function getControllerName(string $type): string
{
if (strpos($type, '.') !== false) {
$type = substr($type, strpos($type, '.') + 1);
}
return \sprintf('sylius.controller.export_data_%s', $type);
}
} |
Thanks a lot ! Prior to your answer, I took the plugin service (sylius.exporter.orders.json), put it in my services.yaml, and commented everything but the class. And it worked ! |
Hi, Where did you register this? I noticed that |
You need to add it in your final class Kernel extends BaseKernel
{
protected function build(ContainerBuilder $container): void
{
$container->addCompilerPass(new RegisterOrderExportButtonPass());
}
} |
Hi, |
Is it possible to disable exporters? I need to export orders, but I don't want the export button to appear on the other resources that are currently available (countries, tax_categories, customer and products).
I could register a CompilerPass and remove the definitions I don't want, but I would like to know if there is another way.
The text was updated successfully, but these errors were encountered: