8000 feature #24303 [FrameworkBundle] allow forms without translations and… · symfony/symfony@b590683 · GitHub
[go: up one dir, main page]

Skip to content

Commit b590683

Browse files
committed
feature #24303 [FrameworkBundle] allow forms without translations and validator (xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle] allow forms without translations and validator | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony/flex#26, symfony/recipes#191, symfony/recipes#193 | License | MIT | Doc PR | The Form component is perfectly usable without the Translation and Validator components. We should allow the same when using the FrameworkBundle to improve the user experience in Symfony Flex applications (see the linked issue). Commits ------- cb6ead1 allow forms without translations and validator
2 parents 4badda9 + cb6ead1 commit b590683

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

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

Lines changed: 12 additions & 6 deletions
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.ty 9FF9 pe_extension.upload.validator');
456+
}
451457
}
452458

453459
/**

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

Lines changed: 1 addition & 1 deletion
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)
0