Skip to content

Commit 4152e62

Browse files
committed
Delete index page import form hook and templates
1 parent f35005d commit 4152e62

File tree

7 files changed

+23
-96
lines changed

7 files changed

+23
-96
lines changed

spec/Controller/ImportDataControllerSpec.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66

77
use FriendsOfSylius\SyliusImportExportPlugin\Controller\ImportDataController;
88
use PhpSpec\ObjectBehavior;
9+
use Sylius\Bundle\ResourceBundle\Controller\RequestConfigurationFactoryInterface;
910
use Sylius\Component\Registry\ServiceRegistryInterface;
11+
use Sylius\Component\Resource\Metadata\RegistryInterface;
1012
use Symfony\Component\Form\FormFactoryInterface;
1113
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
1214

1315
class ImportDataControllerSpec extends ObjectBehavior
1416
{
1517
function let(
18+
RequestConfigurationFactoryInterface $configurationFactory,
19+
RegistryInterface $resourceRegistry,
1620
ServiceRegistryInterface $registry,
1721
FlashBagInterface $flashBag,
1822
FormFactoryInterface $formFactory,
1923
\Twig_Environment $twig
2024
) {
2125
$this->beConstructedWith(
26+
$configurationFactory,
27+
$resourceRegistry,
2228
$registry,
2329
$flashBag,
2430
$formFactory,

spec/DependencyInjection/Compiler/RegisterImporterPassSpec.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace spec\FriendsOfSylius\SyliusImportExportPlugin\DependencyInjection\Compiler;
66

77
use FriendsOfSylius\SyliusImportExportPlugin\DependencyInjection\Compiler\RegisterImporterPass;
8+
use FriendsOfSylius\SyliusImportExportPlugin\Listener\ImportButtonGridListener;
89
use PhpSpec\ObjectBehavior;
910
use Prophecy\Argument;
10-
use Sylius\Bundle\UiBundle\Block\BlockEventListener;
1111
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1212
use Symfony\Component\DependencyInjection\ContainerBuilder;
1313
use Symfony\Component\DependencyInjection\Definition;
@@ -27,7 +27,7 @@ function it_is_initializable()
2727
function it_processes_the_importer_services(
2828
ContainerBuilder $container,
2929
Definition $importerRegistry,
30-
Definition $blockEventDefinition
30+
Definition $importButtonListenerDefinition
3131
) {
3232
$importerType = 'csv';
3333
/**
@@ -47,8 +47,8 @@ function it_processes_the_importer_services(
4747
]);
4848
$container->register(
4949
Argument::type('string'),
50-
BlockEventListener::class
51-
)->willReturn($blockEventDefinition)->shouldBeCalled();
50+
ImportButtonGridListener::class
51+
)->willReturn($importButtonListenerDefinition)->shouldBeCalled();
5252

5353
/**
5454
* prepare the mock for the importerRegistry
@@ -61,23 +61,23 @@ function it_processes_the_importer_services(
6161
/**
6262
* prepare the mock for the definition of the sonata-event
6363
*/
64-
$blockEventDefinition->setAutowired(false)
64+
$importButtonListenerDefinition->setAutowired(false)
6565
->shouldBeCalled()
66-
->willReturn($blockEventDefinition);
66+
->willReturn($importButtonListenerDefinition);
6767

68-
$blockEventDefinition->addArgument(Argument::type('string'))
68+
$importButtonListenerDefinition->addArgument(Argument::type('string'))
6969
->shouldBeCalled()
70-
->willReturn($blockEventDefinition);
70+
->willReturn($importButtonListenerDefinition);
7171

72-
$blockEventDefinition->addTag(
73-
'kernel.event_listener',
72+
$importButtonListenerDefinition->addTag(
73+
'kernel.event_listener',
7474
[
75-
'event' => 'sonata.block.event.sylius.admin.' . $importerType . '.index.after_content',
76-
'method' => 'onBlockEvent',
75+
'event' => 'sylius.grid.admin_' . $importerType,
76+
'method' => 'onSyliusGridAdmin',
7777
]
78-
)
78+
)
7979
->shouldBeCalled()
80-
->willReturn($blockEventDefinition);
80+
->willReturn($importButtonListenerDefinition);
8181

8282
/**
8383
* run the test

src/Controller/ImportDataController.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,6 @@ public function __construct(
5555
$this->flashBag = $flashBag;
5656
}
5757

58-
public function importFormAction(Request $request): Response
59-
{
60-
$importer = $request->attributes->get('resource');
61-
$form = $this->getForm($importer);
62-
63-
$content = $this->twig->render(
64-
'@FOSSyliusImportExportPlugin/Crud/import_form.html.twig',
65-
['form' => $form->createView(), 'resource' => $importer]
66-
);
67-
68-
return new Response($content);
69-
}
70-
7158
public function importAction(Request $request, string $resource): Response
7259
{
7360
$configuration = $this->configurationFactory->create($this->resourceRegistry->get($resource), $request);
@@ -100,19 +87,15 @@ public function importAction(Request $request, string $resource): Response
10087
);
10188
}
10289

103-
private function getForm(string $importerType)
104-
{
105-
return $this->formFactory->create(ImportType::class, null, ['importer_type' => $importerType]);
106-
}
107-
10890
private function import(string $type, string $format, UploadedFile $file): void
10991
{
11092
$name = ImporterRegistry::buildServiceName($type, $format);
11193
/** @var ImporterInterface $service */
11294
$service = $this->registry->get($name);
113-
95+
/** @var string $path */
96+
$path = $file->getRealPath();
11497
/** @var ImporterResult $result */
115-
$result = $service->import($file->getRealPath());
98+
$result = $service->import($path);
11699

117100
$message = sprintf(
118101
'Imported via %s importer (Time taken in ms: %s, Imported %s, Skipped %s, Failed %s)',

src/DependencyInjection/Compiler/RegisterImporterPass.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -41,41 +41,11 @@ public function process(ContainerBuilder $container): void
4141

4242
if ($container->getParameter('sylius.importer.web_ui') && !in_array($type, $typesWithImportButton)) {
4343
$typesWithImportButton[] = $type;
44-
$this->registerImportFormBlockEvent($container, $type);
4544
$this->registerEventListenerForImportButton($container, $type);
4645
}
4746
}
4847
}
4948

50-
private function registerImportFormBlockEvent(ContainerBuilder $container, string $type): void
51-
{
52-
$eventHookName = ImporterRegistry::buildEventHookName($type) . '.import';
53-
54-
if ($container->has($eventHookName)) {
55-
return;
56-
}
57-
58-
if (strpos($type, '.') !== false) {
59-
$type = substr($type, strpos($type, '.') + 1);
60-
}
61-
62-
$container
63-
->register(
64-
$eventHookName,
65-
BlockEventListener::class
66-
)
67-
->setAutowired(false)
68-
->addArgument('@FOSSyliusImportExportPlugin/Crud/import.html.twig')
69-
->addTag(
70-
'kernel.event_listener',
71-
[
72-
'event' => 'sonata.block.event.sylius.admin.' . $type . '.index.after_content',
73-
'method' => 'onBlockEvent',
74-
]
75-
)
76-
;
77-
}
78-
7949
private function registerEventListenerForImportButton(ContainerBuilder $container, string $type): void
8050
{
8151
$serviceId = sprintf('fos_import_export.event_listener.%s_grid.import_button', $type);

src/Importer/ImporterRegistry.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@ public static function buildServiceName(string $type, string $format): string
1818

1919
return sprintf('%s.%s', $type, $format);
2020
}
21-
22-
public static function buildEventHookName(string $type): string
23-
{
24-
return sprintf('%s_%s', self::EVENT_HOOK_NAME_PREFIX_ADMIN_CRUD_AFTER_CONTENT, $type);
25-
}
2621
}

src/Resources/views/Crud/import.html.twig

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/Resources/views/Crud/import_form.html.twig

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)