diff --git a/README.md b/README.md index 75f8dd42..e35ecdf7 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ admin overview panel using the event hook system, ie. `admin/tax-categories/`. #### Notes - - Replace `app.foo` with the name of the resource (under `sylius_resource` config) you want to implement in the following examples. + - Replace `app` and `foo` with the name of the resource (under `sylius_resource` config) you want to implement in the following examples. - Replace `bar` with the name of the format you want to implement in the following examples (csv, json, ...). - Note it is of course also possible to implement a dedicated importer for `app.foo` resource and format `bar`, in case a generic type implementation is not possible. @@ -170,7 +170,7 @@ sylius.importer.foo.bar: - "@sylius.processor.foo" - "@sylius.importer.result" tags: - - { name: sylius.importer, type: app.foo, format: csv } + - { name: sylius.importer, type: foo, domain: app, format: csv } ``` ##### Alternatively implement a custom ResourceImporter _FooImporter_ @@ -192,7 +192,7 @@ sylius.importer.foo.bar: - "@sylius.processor.foo" - "@sylius.importer.result" tags: - - { name: sylius.importer, type: app.foo, format: bar } + - { name: sylius.importer, type: foo, domain: app, format: bar } ``` #### Adding a ResourceProcessor diff --git a/src/DependencyInjection/Compiler/RegisterImporterPass.php b/src/DependencyInjection/Compiler/RegisterImporterPass.php index 7a36552f..0ef90554 100644 --- a/src/DependencyInjection/Compiler/RegisterImporterPass.php +++ b/src/DependencyInjection/Compiler/RegisterImporterPass.php @@ -46,17 +46,18 @@ public function process(ContainerBuilder $container): void $type = $attributes[0]['type']; $format = $attributes[0]['format']; + $domain = $attributes[0]['domain'] ?? null; $name = ImporterRegistry::buildServiceName($type, $format); $importersRegistry->addMethodCall('register', [$name, new Reference($id)]); if ($container->getParameter('sylius.importer.web_ui')) { - $this->registerImportFormBlockEvent($container, $type); + $this->registerImportFormBlockEvent($container, $type, $domain); } } } - private function registerImportFormBlockEvent(ContainerBuilder $container, string $type): void + private function registerImportFormBlockEvent(ContainerBuilder $container, string $type, ?string $domain): void { $eventHookName = $this->buildEventHookName($type); @@ -64,7 +65,7 @@ private function registerImportFormBlockEvent(ContainerBuilder $container, strin return; } - $eventName = $this->buildEventName($type); + $eventName = $this->buildEventName($type, $domain); $templateName = $this->buildTemplateName($type); $container ->register( @@ -92,13 +93,13 @@ private function buildEventHookName(string $type): string return sprintf('app.block_event_listener.admin.crud.after_content_%s.import', $type); } - private function buildEventName(string $type): string + private function buildEventName(string $type, ?string $domain): string { if (isset($this->eventNames[$type])) { return $this->eventNames[$type]; } - $domain = 'sylius'; + $domain = $domain ?? 'sylius'; // backward compatibility with the old configuration if (count(\explode('.', $type)) === 2) { [$domain, $type] = \explode('.', $type);