-
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathSetonoSyliusTermsExtension.php
More file actions
106 lines (96 loc) · 4.14 KB
/
Copy pathSetonoSyliusTermsExtension.php
File metadata and controls
106 lines (96 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
declare(strict_types=1);
namespace Setono\SyliusTermsPlugin\DependencyInjection;
use ReflectionClass;
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use function Symfony\Component\String\u;
final class SetonoSyliusTermsExtension extends AbstractResourceExtension implements PrependExtensionInterface
{
public function load(array $configs, ContainerBuilder $container): void
{
/**
* @psalm-suppress PossiblyNullArgument
*
* @var array{forms: array<class-string, array{label: string|null}>, routing: array{terms: string}, resources: array} $config
*/
$config = $this->processConfiguration($this->getConfiguration([], $container), $configs);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
foreach ($config['forms'] as $form => $formConfig) {
$reflectionClass = new ReflectionClass($form);
$label = $formConfig['label'] ?? sprintf('setono_sylius_terms.form.terms.term_form.%s', u($reflectionClass->getShortName())->snake()->trimSuffix('_type')->toString());
$config['forms'][$form]['label'] = $label;
}
$container->setParameter('setono_sylius_terms.forms', $config['forms']);
$container->setParameter('setono_sylius_terms.terms_path', $config['routing']['terms']);
$loader->load('services.xml');
$this->registerResources(
'setono_sylius_terms',
SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
$config['resources'],
$container,
);
}
public function prepend(ContainerBuilder $container): void
{
$container->prependExtensionConfig('sylius_grid', [
'grids' => [
'setono_sylius_terms_terms' => [
'driver' => [
'name' => 'doctrine/orm',
'options' => [
'class' => '%setono_sylius_terms.model.terms.class%',
],
],
'fields' => [
'code' => [
'type' => 'string',
'label' => 'setono_sylius_terms.ui.code',
],
'name' => [
'type' => 'string',
'label' => 'setono_sylius_terms.ui.name',
],
'channels' => [
'type' => 'twig',
'label' => 'setono_sylius_terms.ui.channels',
'options' => [
'template' => '@SetonoSyliusTermsPlugin/admin/grid/field/channels.html.twig',
],
],
],
'actions' => [
'main' => [
'create' => [
'type' => 'create',
],
],
'item' => [
'update' => [
'type' => 'update',
],
'delete' => [
'type' => 'delete',
],
],
],
],
],
]);
/*$container->prependExtensionConfig('sylius_ui', [
'events' => [
'setono_sylius_terms.admin.terms.create.javascripts' => [
'blocks' => [
'javascripts' => [
'template' => '@SetonoSyliusTermsPlugin/admin/terms/_javascripts.html.twig',
],
],
],
],
]);*/
}
}