loadPhoneNumbersMapField($entity); } protected function loadPhoneNumbersMapField(Entity $entity) { $map = (object) []; $erasedPart = 'ERASED:'; $contactIdList = $entity->getLinkMultipleIdList('contacts'); if (count($contactIdList)) { $contactList = $this->getEntityManager()->getRepository('Contact')->where([ 'id' => $contactIdList ])->select(['id', 'phoneNumber'])->find(); foreach ($contactList as $contact) { $phoneNumber = $contact->get('phoneNumber'); if ($phoneNumber) { if (strpos($phoneNumber, $erasedPart) !== 0) { $key = $contact->getEntityType() . '_' . $contact->id; $map->$key = $phoneNumber; } } } } $leadIdList = $entity->getLinkMultipleIdList('leads'); if (count($leadIdList)) { $leadList = $this->getEntityManager()->getRepository('Lead')->where([ 'id' => $leadIdList ])->select(['id', 'phoneNumber'])->find(); foreach ($leadList as $lead) { $phoneNumber = $lead->get('phoneNumber'); if ($phoneNumber) { if (strpos($phoneNumber, $erasedPart) !== 0) { $key = $lead->getEntityType() . '_' . $lead->id; $map->$key = $phoneNumber; } } } } $entity->set('phoneNumbersMap', $map); } protected function afterUpdateEntity(Entity $entity, $data) { parent::afterUpdateEntity($entity, $data); if (isset($data->contactsIds) || isset($data->leadsIds)) { $this->loadPhoneNumbersMapField($entity); } } }