public function save($object)
{
$this->getDao()->save($object);
$allowedTypes = $object->getClass()->getFieldDefinition($this->getFieldname())->getAllowedTypes();
$collectionItems = $this->getItems();
if (is_array($collectionItems)) {
$index = 0;
foreach ($collectionItems as $collection) {
if ($collection instanceof Fieldcollection\Data\AbstractData) {
if (in_array($collection->getType(), $allowedTypes)) {
$collection->setFieldname($this->getFieldname());
$collection->setIndex($index++);
// set the current object again, this is necessary because the related object in $this->object can change (eg. clone & copy & paste, etc.)
$collection->setObject($object);
$collection->save($object);
} else {
throw new \Exception("Fieldcollection of type " . $collection->getType() . " is not allowed in field: " . $this->getFieldname());
}
}
}
}
}