Improve form behaviour to allow removing of document:

* add button to remove document ;
* fix error when document is removed ;
This commit is contained in:
2020-06-15 15:18:19 +02:00
parent a4c2b93e1c
commit 48b1bec7ea
8 changed files with 165 additions and 15 deletions

View File

@@ -10,14 +10,25 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\Form\CallbackTransformer;
use Doctrine\ORM\EntityManagerInterface;
/**
*
* Form type which allow to join a document
*
* @author Julien Fastré <julien.fastre@champs-libres.coop>
*/
class StoredObjectType extends AbstractType
{
/**
*
* @var EntityManagerInterface
*/
protected $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
@@ -86,6 +97,9 @@ class StoredObjectType extends AbstractType
}
if (NULL === $object->getFilename()) {
// remove the original object
$this->em->remove($object);
return null;
}