You are here

public function OpignoMessageThreadController::redirectToNewThread in Opigno messaging 3.x

Create the new thread with the given user and redirect to its page.

Parameters

int $uid: The user ID to create message thread with.

Return value

\Symfony\Component\HttpFoundation\RedirectResponse|null The redirect response.

1 string reference to 'OpignoMessageThreadController::redirectToNewThread'
opigno_messaging.routing.yml in ./opigno_messaging.routing.yml
opigno_messaging.routing.yml

File

src/Controller/OpignoMessageThreadController.php, line 213

Class

OpignoMessageThreadController
The Opigno messaging controller.

Namespace

Drupal\opigno_messaging\Controller

Code

public function redirectToNewThread(int $uid) : ?RedirectResponse {
  $members = [
    (int) $this->currentUser
      ->id(),
    $uid,
  ];
  $thread = $this->messageService
    ->getThreadForMembers($members);
  if (!$thread instanceof PrivateMessageThreadInterface) {
    return NULL;
  }

  // Prepare the url to the created thread.
  $url = Url::fromRoute('entity.private_message_thread.canonical', [
    'private_message_thread' => $thread
      ->id(),
  ])
    ->toString();
  return new RedirectResponse($url);
}