Hello,
I have been trying out the bundle and so far it has been great.
I ran into an error when trying to add an Image inside a TranslationsType inside my EasyAdmin forms. The field gets rendered as a text input. The widget transformations are not applied.
This is how the field is added :
<?php
namespace App\Controller\Admin;
use A2lix\TranslationFormBundle\Form\Type\TranslationsType;
use App\Entity\Book;
use App\Form\BookLinkType;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\Field;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use JoliCode\MediaBundle\Bridge\EasyAdmin\Field\MediaChoiceField;
use JoliCode\MediaBundle\Bridge\EasyAdmin\Form\Type\MediaChoiceType;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy;
use Symfony\Component\Form\FormBuilderInterface;
class BookCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Book::class;
}
// from https://mediabundle.jolicode.com/bridges/easy-admin/#media-selector-widget does not work in this case
public function configureAssets(Assets $assets): Assets
{
// this should not be needed, but there is a bug in EA with assets in nested forms
// see https://github.com/EasyCorp/EasyAdminBundle/issues/6127
$package = new PathPackage(
'/bundles/jolimediaeasyadmin',
new JsonManifestVersionStrategy(__DIR__ . '/../../../public/bundles/jolimediaeasyadmin/manifest.json'),
);
return $assets
->addCssFile($package->getUrl('joli-media-easy-admin.css'))
->addJsFile($package->getUrl('joli-media-easy-admin.js'))
;
}
public function configureCrud(Crud $crud): Crud
{
return $crud->setEntityLabelInSingular('Book')
->setEntityLabelInPlural('Books');
}
public function configureFields(string $pageName): iterable
{
yield IdField::new('id')->hideOnForm();
yield MediaChoiceField::new('dummy', 'dummy')
->onlyOnForms()
->setFormTypeOption('required', false)
->setFormTypeOption('mapped', false)
->addCssClass('d-none')
;
}
public function createEditFormBuilder(EntityDto $entityDto, KeyValueStore $formOptions, AdminContext $context): FormBuilderInterface
{
$formBuilder = parent::createEditFormBuilder($entityDto, $formOptions, $context);
$formBuilder->add('translations', TranslationsType::class, $this->translationsOptions());
return $formBuilder;
}
private function translationsOptions(): array
{
return [
'translatable_class' => Book::class,
'children_excluded' => ['id', 'translatable', 'locale'],
'builder' => static function (FormBuilderInterface $builder, array $classProperties): void {
$builder->add('image', MediaChoiceType::class, ['required' => false, 'label' => 'Cover']);
},
];
}
}
I tried using the configureAssets override from the documentation : https://mediabundle.jolicode.com/bridges/easy-admin/#media-selector-widget but this did not solve the issue for me.
However just adding a dummy field to my controller fixed the issue :
yield MediaChoiceField::new('dummy', 'dummy')
->onlyOnForms()
->setFormTypeOption('required', false)
->setFormTypeOption('mapped', false)
->addCssClass('d-none')
;
Not yet completely sure how this works and the configureAssets override did not.
I am using :
- php 8.5
- symfony 8.0
- a2lix/translation-form-bundle 4.0.3
- easycorp/easyadmin-bundle 5.0.4
- jolicode/media-bundle 0.3.2
Thanks
Hello,
I have been trying out the bundle and so far it has been great.
I ran into an error when trying to add an Image inside a TranslationsType inside my EasyAdmin forms. The field gets rendered as a text input. The widget transformations are not applied.
This is how the field is added :
I tried using the configureAssets override from the documentation : https://mediabundle.jolicode.com/bridges/easy-admin/#media-selector-widget but this did not solve the issue for me.
However just adding a dummy field to my controller fixed the issue :
Not yet completely sure how this works and the configureAssets override did not.
I am using :
Thanks