[TYPO3-english] Problem updating Collection

Simon Seggewiß info at simonseggewiss.de
Fri Dec 16 23:01:00 CET 2016


Hey guys,

I'm quite new to Typo3 Flow and I have a problem with updating an existing collection.
I have got an entity called "Seo" and one called "Image". One Seo entry could have multiple Images.

After submitting my form, Flow always wants to create new database entries instead of updating the existing ones of the seo entry.
Could anyone please tell me what I am doing wrong?

Here are some code examples:

class Seo {
    /**
     * @var Collection<VKF\Seo\Domain\Model\Image>
     *
     * @ORM\OneToMany(mappedBy="seo")
     */
    protected $images;

    public function __construct()
    {
        $this->images = new ArrayCollection();
    }

    /**
     * @return Collection
     */
    public function getImages()
    {
        return $this->images;
    }

    /**
     * @param Image $image
     */
    public function addImage(Image $image)
    {
        $image->setSeo($this);
        $this->images->add($image);
    }

    /**
     * @param mixed $images
     */
    public function setImages(Collection $images)
    {
        foreach ($images as $image) {
            $image->setSeo($this);
        }
        $this->images = $images;
    }

    /**
     * @param Image $image
     */
    public function removeImage(Image $image)
    {
        $this->images->removeElement($image);
    }

}



class Image {
    /**
     * @var Seo
     *
     * @ORM\ManyToOne(inversedBy="images")
     */
    protected $seo;


    /**
     * @return Seo
     */
    public function getSeo()
    {
        return $this->seo;
    }

    /**
     * @param Seo $seo
     */
    public function setSeo($seo)
    {
        $this->seo = $seo;
    }
}


SeoEditForm:

            <f:for each="{seoEntry.images}" as="image" iteration="iterator">
                            <div class="form-group">
                                <label for="title[{iterator.index}]"><f:translate id="seoEntry.image.title"/></label>
                                <f:form.textfield property="images.{iterator.index}.title" name="seoEntry[images][{iterator.index}].title" class="form-control" value="{image.title}" id="title[{iterator.index}]"/>
                            </div>
                            <div class="form-group">
                                <label for="altTag[{iterator.index}]"><f:translate id="seoEntry.image.altTag"/></label>
                                <f:form.textfield property="images.{iterator.index}.altTag" name="seoEntry[images][{iterator.index}].altTag" class="form-control" value="{image.altTag}" id="altTag[{iterator.index}]"/>
                            </div>
                            <div class="form-group">
                                <label for="url[{iterator.index}]"><f:translate id="seoEntry.image.url"/></label>
                                <f:form.textfield property="images.{iterator.index}.url" name="seoEntry[images][{iterator.index}].url" class="form-control" value="{image.url}" id="url[{iterator.index}]"/>
                            </div>
            </f:for>




More information about the TYPO3-english mailing list