*/ class CaseObj extends Record { /** * @param CaseEntity $entity */ public function beforeCreateEntity(Entity $entity, $data) { parent::beforeCreateEntity($entity, $data); if ($this->user->isPortal()) { if (!$entity->has('accountId')) { if ($this->user->getContactId()) { /** @var ?ContactEntity $contact */ $contact = $this->entityManager ->getEntityById(ContactEntity::ENTITY_TYPE, $this->user->getContactId()); if ($contact && $contact->getAccount()) { $entity->set('accountId', $contact->getAccount()->getId()); } } } if (!$entity->has('contactId')) { if ($this->user->getContactId()) { $entity->set('contactId', $this->user->getContactId()); } } } } public function afterCreateEntity(Entity $entity, $data) { parent::afterCreateEntity($entity, $data); if (!empty($data->emailId)) { /** @var ?Email $email */ $email = $this->entityManager->getEntityById(Email::ENTITY_TYPE, $data->emailId); if ($email && !$email->getParentId() && $this->acl->check($email)) { $email->set([ 'parentType' => CaseEntity::ENTITY_TYPE, 'parentId' => $entity->getId(), ]); $this->entityManager->saveEntity($email); } } } }