public function isValidChild(ChildrenCollectionInterface $collection, PersonaInterface $child) { $errors = []; if ($collection->getParent()->getGender() === self::GENDER_UNDEFINED) { $errors[] = "Can't add child for genderless persona"; } if ($collection->contains($child)) { $errors[] = 'Persona already has this child'; } if ($collection->getParent() === $child) { $errors[] = "Child can't be parent for self"; } return $this->getResult($errors); }
public function addChild(PersonaInterface $child) { $this->children->add($child); // service parents switch ($this->gender) { case self::GENDER_MALE: if (empty($child->getFather())) { $child->setFather($this); } break; case self::GENDER_FEMALE: if (empty($child->getMother())) { $child->setMother($this); } break; } }