EasyAdminBundle icon indicating copy to clipboard operation
EasyAdminBundle copied to clipboard

Assets does not included for embedded crud form fields

Open zorn-v opened this issue 1 year ago • 2 comments

Describe the bug If you have collection (for example) with useEntryCrudForm and in that form you have some fields with added assets (e.g. ImageField), that assets does not included in result html page.

To Reproduce Create entities like

<?php

namespace App\Entity;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Parent
{
    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: Child::class, orphanRemoval: true, cascade: ['persist', 'remove'])]
    public Collection $child;
}
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class Child
{
    #[ORM\ManyToOne(inversedBy: 'child')]
    #[ORM\JoinColumn(nullable: false)]
    public ?Parent $parent = null;

    #[ORM\Column(length: 255, nullable: true)]
    public ?string $photo = null;
}

and crud controllers like

// Parent
    public function configureFields(string $pageName): iterable
    {
        return [
            CollectionField::new('child')
                ->useEntryCrudForm()
        ];
    }
//...
// Child
    public function configureFields(string $pageName): iterable
    {
        return [
            ImageField::new('photo')
        ];
    }
//...

You will see that field-image.js and field-file-upload.js does not included in result html page. In fact it will not change file title for example when you select file for upload etc.

zorn-v avatar Apr 05 '24 09:04 zorn-v

As workaround, include that assets in parent crud controller explicitly.

zorn-v avatar Apr 05 '24 09:04 zorn-v

I might come late, but here's my 2cts.

    public function configureFields(string $pageName): iterable
    {
        return [
            CollectionField::new('child')
                ->addJsFiles(Asset::fromEasyAdminAssetPackage('field-image.js')->onlyOnForms())
                ->addJsFiles(Asset::fromEasyAdminAssetPackage('field-file-upload.js')->onlyOnForms())
                ->useEntryCrudForm()
        ];
    }

(Don't forget namespace imports)

Geolim4 avatar Aug 16 '24 02:08 Geolim4