[TYPO3-mvc] 1:n Relation as multiple select?
g4-lisz at tonarchiv.ch
g4-lisz at tonarchiv.ch
Wed Feb 5 14:43:37 CET 2014
Yes this works. Had to do the same a few days ago (see German list):
Your model needs a array property (getter/setter, no TCA), which takes
the selected UIDs from the form.select viewhelper.
E.g.
Model "House" has 1..n "Room"s
Add a house.roomArray as array() to your House model.
In the form viewhelper add this line:
<f:form.select size="5" multiple="multiple" property="roomArr"
options="{rooms}" optionValueField="uid" optionLabelField="name"/>
Your roomArray Getter/Setter have to handle the Uids from/to the array,
like:
public function getRoomArr() {
$roomarr = array();
foreach ($this->rooms as $room)
$roomarr[] = $room->getUid();
return $roomarr;
}
public function setRoomArr($roomarr) {
$roomRepository =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('GK\Stdapp\Domain\Repository\RoomRepository');
$newStorage =
\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Persistence\ObjectStorage');
foreach($roomarr as $uid)
$newStorage->attach($roomRepository->findByUid($uid));
$this->setRoom($newStorage);
}
This worked for me. But maybe there is a more straight forward solution...
Cheers,
Till
On 02/04/2014 03:57 PM, Stefan Kruse wrote:
> I want to make a 1:n Relation as multiple select field in typo3 backend. Is there a was to do this? I found no solution.
>
> Sorry for double Post.
>
> Regards stefan
>
> Von meinem Sony Xperia™-Smartphone gesendet
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
More information about the TYPO3-project-typo3v4mvc
mailing list