OK, I think I have solved this.
As I am imitating the model "Category" I should be putting only one image for my entity (and this is enough for my purpose).
So here is how it goes : in my module, aside from Main.php, I have 7 php files and one twig file. The entity is called "Author", module is "Librairie" and vendor name is EdB.
The files are:
Controller file Controller/Admin/AuthorEdit.php
Page view file View/Page/Admin/AuthorEdit.php which calls the twig file
the twig file page/myentity_edit/body.twig which calls the input forms, which is
View/Model/Author.php
View/Form/Model/Author.php
and the definition of entities
Model/Author.php
Model/Image/Author/Image.php
and the path to the image storage
Model/Repo/Image/Author/Image.php
The relevant part of the codes are
the definition of image property and getter and setter in Model/Author.php
Code:
/**
* One-to-one relation with category_images table
*
* @var \XLite\Module\EdB\Librairie\Model\Image\Author\Image
*
* @OneToOne (targetEntity="XLite\Module\EdB\Librairie\Model\Image\Author\I
mage", mappedBy="author", cascade={"all"})
*/
protected $image;
...
...
/**
* Get image
*
* @return \XLite\Module\EdB\Librairie\Model\Image\Author\Image
*/
public function getImage()
{
return $this->image;
}
/**
* Set image
*
* @param \XLite\Module\EdB\Librairie\Model\Image\Author\Image $image Image
OPTIONAL
*
* @return void
*/
public function setImage(\XLite\Module\EdB\Librairie\Model\Image\Author\Imag
e $image = null)
{
$this->image = $image;
}
/**
* Check if category has image
*
* @return boolean
*/
public function hasImage()
{
return null !== $this->getImage();
}
(OK, I was too lazy to change some commented out text, but this shouldn't cause the trouble). The definition of the image entity in Model/Image/Author/Image.php
Code:
namespace XLite\Module\EdB\Librairie\Model\Image\Author;
/**
* Author
*
* @Entity
* @Table (name="author_images")
*/
class Image extends \XLite\Model\Base\Image
{
/**
* Relation to a author entity
*
* @var \XLite\Module\EdB\Librairie\Model\Author
*
* @OneToOne (targetEntity="XLite\Module\EdB\Librairie\Model\Author", inve
rsedBy="image")
* @JoinColumn (name="author_id", referencedColumnName="author_id", onDelete
="CASCADE")
*/
protected $author;
...
...
/**
* Set author
*
* @param \XLite\Module\EdB\Librairie\Model\Author $author
* @return Image
*/
public function setAuthor(\XLite\Module\EdB\Librairie\Model\Author $author =
null)
{
$this->author = $author;
return $this;
}
/**
* Get author
*
* @return \XLite\Module\EdB\Librairie\Model\Author
*/
public function getAuthor()
{
return $this->author;
}
(Omitted lines are about alternative texts)
and the image uploader definition in
View/Model/Author.php
Code:
'image' => array(
self::SCHEMA_CLASS => 'XLite\View\FormField\FileUploader\Image',
self::SCHEMA_LABEL => 'Image',
self::SCHEMA_REQUIRED => false,
),
as well as the path setup in Model/Repo/Image/Author/Image.php
Code:
namespace XLite\Module\EdB\Librairie\Model\Repo\Image\Author;
class Image extends \XLite\Model\Repo\Base\Image
{
/**
* Returns the name of the directory within 'root/images' where images store
d
*
* @return string
*/
public function getStorageName()
{
return 'author';
}
}
I hope this helps people having similar issues.