1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\Form\Extension; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Form\AbstractTypeExtension; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\FormType; |
16
|
|
|
use Symfony\Component\Form\FormInterface; |
17
|
|
|
use Symfony\Component\Form\FormView; |
18
|
|
|
use Symfony\Component\OptionsResolver\Options; |
19
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @deprecated Use the symfony help extension |
23
|
|
|
* @see https://symfony.com/doc/current/form/form_customization.html#form-help-form-view |
24
|
|
|
*/ |
25
|
|
|
final class HelpTypeExtension extends AbstractTypeExtension |
26
|
|
|
{ |
27
|
|
|
public function buildView(FormView $view, FormInterface $form, array $options): void |
28
|
|
|
{ |
29
|
|
|
$helpTranslationDomain = $options['help_translation_domain']; |
30
|
|
|
if ($view->parent && null === $helpTranslationDomain) { |
31
|
|
|
$helpTranslationDomain = $view->vars['translation_domain']; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
$view->vars = array_replace($view->vars, [ |
35
|
|
|
'help' => $options['help'], |
36
|
|
|
'help_translation_domain' => $helpTranslationDomain, |
37
|
|
|
]); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function configureOptions(OptionsResolver $resolver): void |
41
|
|
|
{ |
42
|
|
|
$helpTranslationDomainNormalizer = static function (Options $options, $helpTranslationDomain) { |
43
|
|
|
if (null === $helpTranslationDomain && $options->offsetExists('translation_domain')) { |
44
|
|
|
return $options->offsetGet('translation_domain'); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $helpTranslationDomain; |
48
|
|
|
}; |
49
|
|
|
|
50
|
|
|
$resolver->setDefaults([ |
51
|
|
|
'help' => null, |
52
|
|
|
'help_translation_domain' => null, |
53
|
|
|
]); |
54
|
|
|
|
55
|
|
|
$resolver->setNormalizer('help_translation_domain', $helpTranslationDomainNormalizer); |
56
|
|
|
|
57
|
|
|
$resolver->setAllowedTypes('help', ['null', 'string']); |
58
|
|
|
$resolver->setAllowedTypes('help_translation_domain', ['null', 'bool', 'string']); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public static function getExtendedTypes(): iterable |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
FormType::class, |
65
|
|
|
]; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|