public function normalize($entity)
{
$key = $this->mapping['fieldname'];
$accessor = 'get' . ucfirst($key);
$outerCollection = $entity->{$accessor}();
if (!$outerCollection instanceof RepeatingFieldCollection) {
$collection = new RepeatingFieldCollection($this->em, $this->mapping);
$collection->setName($key);
if (is_array($outerCollection)) {
foreach ($outerCollection as $group => $fields) {
if (is_array($fields)) {
$collection->addFromArray($fields, $group, $entity);
}
}
}
$setter = 'set' . ucfirst($key);
$entity->{$setter}($collection);
}
}