/** * @param Recipient $recipient * * @return array */ public function createRecipientData(Recipient $recipient) { $data = ['key' => $recipient->getId()]; if ($recipientEntity = $recipient->getEntity()) { $data = array_merge($data, ['contextText' => $recipient->getEntity()->getLabel(), 'contextValue' => ['entityClass' => $recipient->getEntity()->getClass(), 'entityId' => $recipient->getEntity()->getId()], 'organization' => $recipient->getEntity()->getOrganization()]); } return ['id' => $recipient->getId(), 'text' => $recipient->getName(), 'data' => json_encode($data)]; }