@@ -46,9 +46,12 @@ public function load(array $configs, ContainerBuilder $container)
4646
4747 $ container ->setParameter ('php_translation.locales ' , $ config ['locales ' ]);
4848 $ container ->setParameter ('php_translation.default_locale ' , isset ($ config ['default_locale ' ]) ? $ config ['default_locale ' ] : $ container ->getParameter ('kernel.default_locale ' ));
49+ $ this ->handleConfigNode ($ container , $ config );
4950
5051 if ($ config ['webui ' ]['enabled ' ]) {
5152 $ this ->enableWebUi ($ container , $ config );
53+ } else {
54+ $ container ->setParameter ('php_translation.webui.enabled ' , false );
5255 }
5356
5457 if ($ config ['symfony_profiler ' ]['enabled ' ]) {
@@ -71,13 +74,24 @@ public function load(array $configs, ContainerBuilder $container)
7174 $ loader ->load ('auto_translation.yml ' );
7275 $ this ->enableFallbackAutoTranslator ($ container , $ config );
7376 }
77+ }
7478
79+ /**
80+ * Handle the config node to prepare the config manager.
81+ *
82+ * @param ContainerBuilder $container
83+ * @param array $config
84+ */
85+ private function handleConfigNode (ContainerBuilder $ container , array $ config )
86+ {
87+ // $first will be the "default" configuration.
7588 $ first = null ;
7689 foreach ($ config ['configs ' ] as $ name => &$ c ) {
7790 if ($ first === null || $ name === 'default ' ) {
7891 $ first = $ name ;
7992 }
8093 if (empty ($ c ['project_root ' ])) {
94+ // Add a project root of none is set.
8195 $ c ['project_root ' ] = dirname ($ container ->getParameter ('kernel.root_dir ' ));
8296 }
8397
@@ -104,19 +118,40 @@ public function load(array $configs, ContainerBuilder $container)
104118
105119 if ($ first !== null ) {
106120 // Create some aliases for the default storage
107- $ container ->setAlias ('php_translation.storage ' , 'php_translation.storage. ' .$ first );
108- $ container ->setAlias ('php_translation.storage.default ' , 'php_translation.storage. ' .$ first );
121+ $ container ->setAlias (
122+ 'php_translation.storage ' ,
123+ 'php_translation.storage. ' .$ first
124+ );
125+ $ container ->setAlias (
126+ 'php_translation.storage.default ' ,
127+ 'php_translation.storage. ' .$ first
128+ );
109129 }
110130
111131 $ container ->getDefinition ('php_translation.configuration_manager ' )
112132 ->replaceArgument (0 , $ config ['configs ' ]);
113133 }
114134
115- private function enableWebUi (ContainerBuilder $ container , $ config )
135+ /**
136+ * Handle config for WebUI.
137+ *
138+ * @param ContainerBuilder $container
139+ * @param array $config
140+ */
141+ private function enableWebUi (ContainerBuilder $ container , array $ config )
116142 {
143+ $ container ->setParameter ('php_translation.webui.enabled ' , true );
144+ $ container ->setParameter ('php_translation.webui.allow_create ' , $ config ['webui ' ]['allow_create ' ]);
145+ $ container ->setParameter ('php_translation.webui.allow_delete ' , $ config ['webui ' ]['allow_delete ' ]);
117146 }
118147
119- private function enableEditInPlace (ContainerBuilder $ container , $ config )
148+ /**
149+ * Handle config for EditInPlace.
150+ *
151+ * @param ContainerBuilder $container
152+ * @param array $config
153+ */
154+ private function enableEditInPlace (ContainerBuilder $ container , array $ config )
120155 {
121156 $ name = $ config ['edit_in_place ' ]['config_name ' ];
122157
@@ -134,12 +169,24 @@ private function enableEditInPlace(ContainerBuilder $container, $config)
134169 $ def ->replaceArgument (1 , $ activatorRef );
135170 }
136171
137- private function enableSymfonyProfiler (ContainerBuilder $ container , $ config )
172+ /**
173+ * Handle config for Symfony Profiler.
174+ *
175+ * @param ContainerBuilder $container
176+ * @param array $config
177+ */
178+ private function enableSymfonyProfiler (ContainerBuilder $ container , array $ config )
138179 {
139180 $ container ->setParameter ('php_translation.toolbar.allow_edit ' , $ config ['symfony_profiler ' ]['allow_edit ' ]);
140181 }
141182
142- private function enableFallbackAutoTranslator (ContainerBuilder $ container , $ config )
183+ /**
184+ * Handle config for fallback auto translate.
185+ *
186+ * @param ContainerBuilder $container
187+ * @param array $config
188+ */
189+ private function enableFallbackAutoTranslator (ContainerBuilder $ container , array $ config )
143190 {
144191 $ externalTranslatorId = 'php_translation.translator_service. ' .$ config ['fallback_translation ' ]['service ' ];
145192 $ externalTranslatorDef = $ container ->getDefinition ($ externalTranslatorId );
@@ -150,6 +197,9 @@ private function enableFallbackAutoTranslator(ContainerBuilder $container, $conf
150197 $ container ->setParameter ('php_translation.translator_service.api_key ' , $ config ['fallback_translation ' ]['api_key ' ]);
151198 }
152199
200+ /**
201+ * {@inheritdoc}
202+ */
153203 public function getAlias ()
154204 {
155205 return 'translation ' ;
0 commit comments