Reputation: 716
I am using Uploadable extension and very happy with that. I have entity with one field as an Uploadable (photo), and another field is annotation for that photo (annotation). When I first create entity I choose the file, and put annotation and everything works okay, but when I want to update just annotation it loses the stored path of the previously uploaded photo. Is there a way to keep old values if null coming for that field?
This is my entity.
/**
* Photo
*
* @ORM\Table()
* @ORM\Entity
* @Gedmo\Uploadable(
* path="up/photo",
* allowOverwrite=false,
* appendNumber=true,
* allowedTypes="image/jpeg,image/pjpeg,image/png,image/x-png"
* )
*/
class Photo
{
/**
* @var array
*
* @Gedmo\Translatable
* @ORM\Column(name="annotation", type="string", length=255, nullable=true)
*/
private $annotation;
/**
* @var string
*
* @Gedmo\UploadableFilePath
* @Assert\File(
* mimeTypes={"image/jpeg", "image/pjpeg", "image/png", "image/x-png"}
* )
* @ORM\Column(name="photo", type="string", length=255)
*/
private $photo;
And this is my Controller part:
if ($entity->getPhoto()) {
$uploadableManager = $this->get('stof_doctrine_extensions.uploadable.manager');
$uploadableManager->markEntityToUpload($entity, $entity->getPhoto());
}
Upvotes: 0
Views: 589
Reputation: 5542
You can change setter on your entity:
public function setPhoto($photo) {
if (!$photo) {return $this;}
$this->photo = $photo;
return $this;
Upvotes: 0