public function setFromPost(array $formValues, Entity\Content $entity) { if (isset($formValues['relation'])) { $flatVals = $formValues['relation']; } else { $flatVals = $formValues; } foreach ($flatVals as $field => $values) { if (!is_array($values)) { continue; } foreach ($values as $val) { if (!$val) { continue; } $newEntity = new Entity\Relations(['from_contenttype' => (string) $entity->getContenttype(), 'from_id' => $entity->getId(), 'to_contenttype' => $field, 'to_id' => $val]); $this->add($newEntity); } } }