Closed cmarsaudon687 closed 1 year ago
Hello @cmarsaudon687 as tu trouve une solution ? Je tente de faire quelque chose de similaire et je suis en galere
Hello @chrisVdd , et non... je n'ai pas trouvé de solution, j'ai donc laissé tout cela dans le même block... Si tu trouves la solution, stp pourrais tu me la partager ? J'ai passé plusieurs heures dessus sans y parvenir. Bon courage à toi
I've recently done it inside EasyAdmin. partial translations macro is indeed the way to go. I've copied it to templates directory and customized the view, but code remains mostly the same. That's why if you
{% import "@A2lixTranslationForm/macros_bootstrap_5.html.twig" as a2lixTranslations %}
{{ a2lixTranslations.partialTranslations(editForm.translations, ['title','description']) }}
instead of
{% import "partial_translations.html.twig" as translations %}
{{ translations.partial(form.translations, ['title','description']) }}
in the files below you should be fine.
The actual files:
final class InitialTranslationsField implements FieldInterface
{
use FieldTrait;
public static function new(
string $propertyName,
?string $label = null,
array $fieldsConfig = [],
array $options = [],
array $shownFields = [],
): self {
return (new self())
->setProperty($propertyName)
->setRequired(true)
->setLabel(false)
->hideOnIndex()
->setFormType(\A2lix\TranslationFormBundle\Form\Type\TranslationsType::class)
->setFormTypeOptions([
'fields' => $fieldsConfig,
])
->setFormTypeOptions($options)
->setCustomOption('shownFields', $shownFields)
->addFormTheme('initial_translations.html.twig')
;
}
}
final class AdditionalTranslationsField implements FieldInterface
{
use FieldTrait;
public static function new(
string $propertyName,
?string $label = null,
array $shownFields = [],
): self {
return (new self())
->setProperty($propertyName)
->setLabel(false)
->hideOnIndex()
->setFormType(AdditionalTranslationsType::class)
->setFormTypeOption('mapped', false)
->setCustomOption('shownFields', $shownFields)
->addFormTheme('additional_translations.html.twig')
;
}
}
final class AdditionalTranslationsType extends AbstractType
{
public function getBlockPrefix(): string
{
return 'additional_translations';
}
}
// initial_translations.html.twig
{% block a2lix_translations_widget %}
{% import "partial_translations.html.twig" as translations %}
{{ translations.partial(form, form.vars.ea_crud_form.ea_field.customOptions.get('shownFields')) }}
{% endblock %}
// additional_translations.html.twig
{% block additional_translations_widget %}
{% import "partial_translations.html.twig" as translations %}
{{ translations.partial(form.parent.translations, form.vars.ea_crud_form.ea_field.customOptions.get('shownFields')) }}
{% endblock %}
First translations are always using InitialTranslationsField, additional ones in different tabs use ... AdditionalTranslationsField. All fields are defined in InitialTranslationsField, in AdditionalTranslationsField I only define what to display:
public function configureFields(string $pageName): iterable
{
return [
FormField::addTab('tab1'),
InitialTranslationsField::new('translations', 'translations', [
'title' => [
'label' => 'title',
],
'description' => [
'label' => 'description',
],
'allFieldsGoHere' => [
'label' => 'all fields',
],
'fromOtherTabsToo' => [
'label' => 'label'
]
],
[],
['title', 'description']
),
FormField::addTab('tab2'),
AdditionalTranslationsField::new('moreTranslations',
shownFields: [
'allFieldsGoHere',
],
),
FormField::addTab('tab3'),
AdditionalTranslationsField::new('andMoreTranslations',
shownFields: [
'fromOtherTabsToo',
],
),
];
}
Hope it helps somebody in the future who finds this issue, cheers
@SzymonKaminski ! Thank you very much for the share ! I'll try this soon.
@SzymonKaminski all is right, that's work fine !! Thanks a lot !
Awesome, exactly what i need. Thanks for sharing!
Bonjour à tous,
Symfony 5 / EasyAdmin 4 / PHP8 Dîtes moi, est-il possible dans un CrudController d'appeler la property translations à plusieurs endroits ? Je souhaiterais en effet, dans un CrudController, gérer certains champs dans un onglet, et d'autres trads dans un autre onglet, j'ai donc pour le moment tenter d'appeler :
FormField::addTab('Onglet 1'),
TranslationField::new('translations', '', $fieldsconfig1)->hideOnIndex(),
FormField::addTab('Onglet 2'),
TranslationField::new('translations', '', $fieldsconfig2)->hideOnIndex(),
avec à chaque fois les champs voulus, mais l'intégralité des champs apparaît toujours lors du dernier appel. Une idée ?
En vous remerciant par avance !
EDIT : J'ai tenté d'utiliser les partialTranslations macro, mais n'ai pas réussi à les coupler avec EasyAdmin.. Si quelqu'un a un exemple concret, je suis preneur ! Merci beaucoup