Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- vich_uploader:
- db_driver: orm
- mappings:
- image_uploads:
- uri_prefix: '%path.image_uploads%'
- upload_destination: '%kernel.project_dir%/public%path.image_uploads%'
- parameters:
- path.image_uploads: '/assets/images/uploads'
- ContactPage:
- class: AppEntityContactPage
- label: 'Contact'
- list: //image not shown
- fields:
- - 'title'
- - 'content'
- - { property: 'image', type: 'image', basePath: '%path.image_uploads%' } //I also tried with the public prefix
- form: //works as intended
- title: '%%entity_label%%'
- fields:
- - 'title'
- - { property: 'content', type: 'FOSCKEditorBundleFormTypeCKEditorType' }
- - { property: 'imageFile', type: 'vich_image', basePath: '%path.image_uploads%' }
- - { property: 'imageAlt', label: 'Alt tag' }
- show: //image not shown
- title: '%%entity_label%%'
- fields:
- - 'title'
- - 'content'
- - { property: 'image', type: 'image' }
- - { property: 'imageAlt', label: 'Alt tag' }
- use VichUploaderBundleMappingAnnotation as Vich;
- use SymfonyComponentHttpFoundationFileFile;
- /**
- * @ORMEntity
- * @VichUploadable
- */
- class ContactPage
- {
- /**
- * @ORMColumn(type="string", length=255, nullable=true)
- * @var string
- */
- private $image;
- /**
- * @VichUploadableField(mapping="image_uploads", fileNameProperty="image")
- * @var File
- */
- private $imageFile;
- /**
- * @return string|null
- */
- public function getImage(): ?string
- {
- return $this->image;
- }
- /**
- * @param string|null $image
- * @return ContactPage
- */
- public function setImage(string $image): self
- {
- $this->image = $image;
- return $this;
- }
- /**
- * @return File|null
- */
- public function getImageFile(): ?File
- {
- return $this->imageFile;
- }
- /**
- * @param File $imageFile
- */
- public function setImageFile(File $imageFile = null): void
- {
- $this->imageFile = $imageFile;
- if ($imageFile) {
- $this->updatedAt = new DateTime('now');
- }
- }
- }
Add Comment
Please, Sign In to add comment