How can I make thus field use the template?
Following the documentation does not seem to help. What am I missing?
I’m trying to render it on this crud controller field:
$translationContents = CollectionField::new('translationKeys')
->setTemplatePath('admin/translation_content.html.twig')
->setFormTypeOptions([
'entry_type' => TranslationType::class,
'by_reference' => false,
]);
This is my custom type:
class TranslationType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', TextType::class, [
'label' => 'Key',
])
->add('translationContent', CollectionType::class, [
'entry_type' => TranslationContentType::class,
'label' => false,
'allow_add' => true,
'allow_delete' => true,
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => TranslationKey::class,
]);
}
public function getBlockPrefix()
{
return 'translation_key';
}
}
This is the other custom type that renders inside the one before:
class TranslationContentType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('locale', EntityType::class, [
'class' => Locale::class,
'choice_label' => 'code', // Assuming your Locale entity has a 'code' property
'label' => 'Locale',
])
->add('name', TextType::class, [
'label' => 'Translation Content',
])
->add('tag', IntegerType::class, [
'label' => 'tag',
'attr' => [
'min' => 0,
'max' => 3
],
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => TranslationContent::class,
]);
}
}
this is the template I’m trying to use:
{% block translation_key_widget %}
{{ dump('Template loaded!') }}
{% for child in form.children|filter(child => not child.rendered) %}
<div class="form-group">
<p> test</p>
{{ form_label(child) }}
{{ form_widget(child) }}
{{ form_help(child) }}
{{ form_errors(child) }}
</div>
{% endfor %}
{% endblock %}
I’ve added this to twig.yaml
form_themes:
- 'admin/translation_content.html.twig'