Skip to content

Commit cb6ead1

Browse files
committed
allow forms without translations and validator
1 parent 4badda9 commit cb6ead1

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

+12-6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
7575
use Symfony\Component\Stopwatch\Stopwatch;
7676
use Symfony\Component\Translation\Command\XliffLintCommand as BaseXliffLintCommand;
77+
use Symfony\Component\Translation\Translator;
7778
use Symfony\Component\Validator\ConstraintValidatorInterface;
7879
use Symfony\Component\Validator\ObjectInitializerInterface;
7980
use Symfony\Component\WebLink\HttpHeaderSerializer;
@@ -189,15 +190,13 @@ public function load(array $configs, ContainerBuilder $container)
189190
throw new LogicException('Translation support cannot be enabled as the Translation component is not installed.');
190191
}
191192

192-
if (!class_exists('Symfony\Component\Translation\Translator') && $this->isConfigEnabled($container, $config['form'])) {
193-
throw new LogicException('Form support cannot be enabled as the Translation component is not installed.');
194-
}
195-
196193
if (!class_exists('Symfony\Component\Translation\Translator') && $this->isConfigEnabled($container, $config['validation'])) {
197194
throw new LogicException('Validation support cannot be enabled as the Translation component is not installed.');
198195
}
199196

200-
$loader->load('identity_translator.xml');
197+
if (class_exists(Translator::class)) {
198+
$loader->load('identity_translator.xml');
199+
}
201200
}
202201

203202
if (isset($config['secret'])) {
@@ -250,7 +249,10 @@ public function load(array $configs, ContainerBuilder $container)
250249
$config['validation']['enabled'] = true;
251250

252251
if (!class_exists('Symfony\Component\Validator\Validation')) {
253-
throw new LogicException('The Validator component is required to use the Form component.');
252+
$container->setParameter('validator.translation_domain', 'validators');
253+
254+
$container->removeDefinition('form.type_extension.form.validator');
255+
$container->removeDefinition('form.type_guesser.validator');
254256
}
255257
} else {
256258
$container->removeDefinition('Symfony\Component\Form\Command\DebugCommand');
@@ -448,6 +450,10 @@ private function registerFormConfiguration($config, ContainerBuilder $container,
448450
} else {
449451
$container->setParameter('form.type_extension.csrf.enabled', false);
450452
}
453+
454+
if (!class_exists(Translator::class)) {
455+
$container->removeDefinition('form.type_extension.upload.validator');
456+
}
451457
}
452458

453459
/**

src/Symfony/Bundle/FrameworkBundle/Resources/config/form_csrf.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<argument type="service" id="security.csrf.token_manager" />
1313
<argument>%form.type_extension.csrf.enabled%</argument>
1414
<argument>%form.type_extension.csrf.field_name%</argument>
15-
<argument type="service" id="translator" />
15+
<argument type="service" id="translator" on-invalid="null" />
1616
<argument>%validator.translation_domain%</argument>
1717
<argument type="service" id="form.server_params" />
1818
</service>

0 commit comments

Comments
 (0)