entityManager = $entityManager; $this->aclManager = $aclManager; } public function checkEdit(User $user, EmailAddress $emailAddress, Entity $excludeEntity): bool { $entityWithSameAddressList = $this->entityManager ->getRepository('EmailAddress') ->getEntityListByAddressId($emailAddress->getId(), $excludeEntity); foreach ($entityWithSameAddressList as $e) { if ($this->aclManager->checkEntityEdit($user, $e)) { continue; } if ( $e->getEntityType() === 'User' && $e->isPortal() && $excludeEntity->getEntityType() === 'Contact' && $e->get('contactId') === $excludeEntity->getEntityType() ) { continue; } return false; } return true; } }