Reputation: 121
I'm wondering how I can add a file-upload
to my resource. I'm using the SyliusResourceBundle
so all controllers are generated for me.
Routing:
app_product:
resource: |
alias: app.product
except: ['show']
section: admin
grid: app_admin_product
templates: Admin/Crud
form: App\Form\Type\ProductType
type: sylius.resource
ProductType
is my custom form and it has a FileType
. I can change this, but the problem is how to handle the upload. When I look into Sylius' controller I see two events being fired:
Sylius\Bundle\ResourceBundle\Controller\ResourceController:~191
$event = $this->eventDispatcher->dispatchPreEvent(ResourceActions::CREATE, $configuration, $newResource);
I've tried creating a custom EventListener
extending the EventSubscriberInterface
and I've tried registering a service that listens specifically to name: kernel.event_listener, event: sylius.product.pre_create
but it won't take for some reason. And even if it does!
Will it allow me to modify $newResource
so the chosen image is saved to the database?
Upvotes: 0
Views: 713
Reputation: 517
Sylius has the capability make any resource entity have images. However, you can use this capability to upload any files, but it won't be able to render anything else except images without additional code to handle other formats. Here's a PR that aimed to make this capability generic and cover any formats: https://github.com/Sylius/Sylius/pull/9224 It was not merged because of multiple BC Breaks, but you can extract the code to your application.
Upvotes: 0