$media = $this->assertMediaExists($params->media_id);
$comment = $this->em()->create('EWR\Medio:Comment');
$mentions = new \XF\Str\MentionFormatter();
$message = $mentions->getMentionsBbCode($this->plugin('XF:Editor')->fromInput('message'));
$mentionUsers = $mentions->getMentionedUsers();
$mentionUsers = $this->finder('XF:User')
->with(['Profile','Option'])
->where('user_id', array_keys($mentionUsers))
->fetch();
$form = $this->formAction();
$form->basicEntitySave($comment, [
'media_id' => $media->media_id,
'comment_message' => $message,
]);
$form->run();
foreach ($mentionUsers AS $user)
{
if ($comment->user_id != $user->user_id)
{
$alertRepo = \XF::repository('XF:UserAlert');
$alertRepo->alertFromUser($user, $comment->User, 'ewr_medio_comment', $comment->comment_id, 'mention');
}
}