getUser()->isPortal()) { if (!$entity->has('accountId')) { if ($this->getUser()->get('contactId')) { $contact = $this->getEntityManager()->getEntity('Contact', $this->getUser()->get('contactId')); if ($contact && $contact->get('accountId')) { $entity->set('accountId', $contact->get('accountId')); } } } if (!$entity->has('contactId')) { if ($this->getUser()->get('contactId')) { $entity->set('contactId', $this->getUser()->get('contactId')); } } } } public function afterCreateEntity(Entity $entity, $data) { parent::afterCreateEntity($entity, $data); if (!empty($data->emailId)) { $email = $this->getEntityManager()->getEntity('Email', $data->emailId); if ($email && !$email->get('parentId')) { $email->set(array( 'parentType' => 'Case', 'parentId' => $entity->id )); $this->getEntityManager()->saveEntity($email); } } } public function getEmailAddressList($id) { $entity = $this->getEntity($id); $forbiddenFieldList = $this->getAcl()->getScopeForbiddenFieldList($this->getEntityType()); $list = []; $emailAddressList = []; if (!in_array('contact', $forbiddenFieldList) && $this->getAcl()->checkScope('Contact')) { if ($entity->get('contactId')) { $contact = $this->getEntityManager()->getEntity('Contact', $entity->get('contactId')); if ($contact && $contact->get('emailAddress')) { $emailAddress = $contact->get('emailAddress'); if ($this->getAcl()->checkEntity($contact)) { $list[] = (object) [ 'emailAddress' => $emailAddress, 'name' => $contact->get('name'), 'entityType' => 'Contact' ]; $emailAddressList[] = $emailAddress; } } } } if (!in_array('contacts', $forbiddenFieldList) && $this->getAcl()->checkScope('Contact')) { $contactIdList = $entity->getLinkMultipleIdList('contacts'); if (count($contactIdList)) { $contactForbiddenFieldList = $this->getAcl()->getScopeForbiddenFieldList('Contact'); if (!in_array('emailAddress', $contactForbiddenFieldList)) { $selectManager = $this->getSelectManagerFactory()->create('Contact'); $selectParams = $selectManager->getEmptySelectParams(); $selectManager->applyAccess($selectParams); $contactList = $this->getEntityManager()->getRepository('Contact')->select(['id', 'emailAddress', 'name'])->where([ 'id' => $contactIdList ])->find($selectParams); foreach ($contactList as $contact) { $emailAddress = $contact->get('emailAddress'); if ($emailAddress && !in_array($emailAddress, $emailAddressList)) { $list[] = (object) [ 'emailAddress' => $emailAddress, 'name' => $contact->get('name'), 'entityType' => 'Contact' ]; $emailAddressList[] = $emailAddress; } } } } } if (empty($list)) { if (!in_array('account', $forbiddenFieldList) && $this->getAcl()->checkScope('Account')) { if ($entity->get('accountId')) { $account = $this->getEntityManager()->getEntity('Account', $entity->get('accountId')); if ($account && $account->get('emailAddress')) { $emailAddress = $account->get('emailAddress'); if ($this->getAcl()->checkEntity($account)) { $list[] = (object) [ 'emailAddress' => $emailAddress, 'name' => $account->get('name'), 'entityType' => 'Account' ]; $emailAddressList[] = $emailAddress; } } } } } if (empty($list)) { if (!in_array('lead', $forbiddenFieldList) && $this->getAcl()->checkScope('Lead')) { if ($entity->get('leadId')) { $lead = $this->getEntityManager()->getEntity('Lead', $entity->get('leadId')); if ($lead && $lead->get('emailAddress')) { $emailAddress = $lead->get('emailAddress'); if ($this->getAcl()->checkEntity($lead)) { $list[] = (object) [ 'emailAddress' => $emailAddress, 'name' => $lead->get('name'), 'entityType' => 'Lead' ]; $emailAddressList[] = $emailAddress; } } } } } return $list; } }