/** * @param RepeatingFieldCollection $collection * * @return RepeatingFieldCollection[] */ public function update(RepeatingFieldCollection $collection) { $updated = []; // First give priority to already existing entities foreach ($collection->flatten() as $entity) { $master = $this->getOriginal($entity); $master->setValue($entity->getValue()); $master->setFieldtype($entity->getFieldtype()); $master->handleStorage($this->getFieldType($entity->getFieldname())); $updated[] = $master; } $deleted = []; foreach ($this->flatten() as $old) { if (!in_array($old, $updated)) { $deleted[] = $old; } } // Clear the collection so that we re-add only the updated elements $this->clear(); foreach ($updated as $new) { $this->add($new); } return $deleted; }