protected function AjaxController::loadThread in Private Message 8
Same name and namespace in other branches
- 8.2 src/Controller/AjaxController.php \Drupal\private_message\Controller\AjaxController::loadThread()
Load a private message thread to be dynamically inserted into the page.
Parameters
Drupal\Core\Ajax\AjaxResponse $response: The response to which any commands should be attached.
1 call to AjaxController::loadThread()
- AjaxController::ajaxCallback in src/
Controller/ AjaxController.php - Create AJAX responses for JavaScript requests.
File
- src/
Controller/ AjaxController.php, line 344
Class
- AjaxController
- Controller to handle Ajax requests.
Namespace
Drupal\private_message\ControllerCode
protected function loadThread(AjaxResponse $response) {
$thread_id = $this->requestStack
->getCurrentRequest()
->get('id');
if ($thread_id) {
$thread = PrivateMessageThread::load($thread_id);
if ($thread && $thread
->access('view', $this->currentUser)) {
$this->privateMessageService
->updateLastCheckTime();
$view_builder = $this->entityManager
->getViewBuilder('private_message_thread');
$renderable = $view_builder
->view($thread);
$rendered_thread = $this->renderer
->renderRoot($renderable);
$index = array_search('private_message/private_message_thread', $renderable['#attached']['library']);
unset($renderable['#attached']['library'][$index]);
$response
->setAttachments($renderable['#attached']);
$response
->addCommand(new PrivateMessageInsertThreadCommand($rendered_thread));
$unread_thread_count = $this->privateMessageService
->getUnreadThreadCount();
$response
->addCommand(new PrivateMessageUpdateUnreadThreadCountCommand($unread_thread_count));
}
}
}