Deleting files within the Symfony Input Widget


Here is a solution for a problem we ran into while working with Symfony.

Problem Description

When using the widget sfWidgetFormInputFileEditable in a form that is embedded using the embedRelation method, file deletion will not work.

For example, suppose that you have two tables named Item and ItemPhoto and they are connected to the relation name ‘Photos’ like so:

class ItemForm extends BaseItemForm {
      public function configure() {

In that case, trying to delete a file with the delete checkbox would not work.


Instead of using a relation name, embed the relation as an alias like this (SomeAlias being any word):

$this->embedRelation('Photos as SomeAlias');

Let us know if you have any questions!